Read data from a mongodb database using vuejs
up vote
1
down vote
favorite
I'm creating a web application to visualize in real time the temperature of my room. Currently I read the value with raspberry and then load the database mongodb. Now to display it in real time on my browser how do I do it? I'm using node.js and vue.js together with express. How do I pass the value to vue.js in real time?
var App = Vue.component('App',{
template: "<h1> {{title}} </h1>",
data() {
let test= "hello";
return {title: test};
}
});
new Vue({
el:"#app"
});
<div id="app">
<App></App>
</div>
node.js mongodb express vue.js
add a comment |
up vote
1
down vote
favorite
I'm creating a web application to visualize in real time the temperature of my room. Currently I read the value with raspberry and then load the database mongodb. Now to display it in real time on my browser how do I do it? I'm using node.js and vue.js together with express. How do I pass the value to vue.js in real time?
var App = Vue.component('App',{
template: "<h1> {{title}} </h1>",
data() {
let test= "hello";
return {title: test};
}
});
new Vue({
el:"#app"
});
<div id="app">
<App></App>
</div>
node.js mongodb express vue.js
did you make an API?
– Boussadjra Brahim
Nov 11 at 15:40
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm creating a web application to visualize in real time the temperature of my room. Currently I read the value with raspberry and then load the database mongodb. Now to display it in real time on my browser how do I do it? I'm using node.js and vue.js together with express. How do I pass the value to vue.js in real time?
var App = Vue.component('App',{
template: "<h1> {{title}} </h1>",
data() {
let test= "hello";
return {title: test};
}
});
new Vue({
el:"#app"
});
<div id="app">
<App></App>
</div>
node.js mongodb express vue.js
I'm creating a web application to visualize in real time the temperature of my room. Currently I read the value with raspberry and then load the database mongodb. Now to display it in real time on my browser how do I do it? I'm using node.js and vue.js together with express. How do I pass the value to vue.js in real time?
var App = Vue.component('App',{
template: "<h1> {{title}} </h1>",
data() {
let test= "hello";
return {title: test};
}
});
new Vue({
el:"#app"
});
<div id="app">
<App></App>
</div>
var App = Vue.component('App',{
template: "<h1> {{title}} </h1>",
data() {
let test= "hello";
return {title: test};
}
});
new Vue({
el:"#app"
});
<div id="app">
<App></App>
</div>
var App = Vue.component('App',{
template: "<h1> {{title}} </h1>",
data() {
let test= "hello";
return {title: test};
}
});
new Vue({
el:"#app"
});
<div id="app">
<App></App>
</div>
node.js mongodb express vue.js
node.js mongodb express vue.js
asked Nov 11 at 13:48
Salvatore Raccardi
156
156
did you make an API?
– Boussadjra Brahim
Nov 11 at 15:40
add a comment |
did you make an API?
– Boussadjra Brahim
Nov 11 at 15:40
did you make an API?
– Boussadjra Brahim
Nov 11 at 15:40
did you make an API?
– Boussadjra Brahim
Nov 11 at 15:40
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Your code in backend should be like this :
//get the value from db
//create a variable tmp that will receives temperature from db
let tmp;
var router = express.Router();
router.get('/temperature', function(req, res) {
res.json({
temperature: tmp
});
});
app.use('/api', router);
in the front you have access to that api :
localhost:8080/api/temperature
And using axios you could make call to your backend and get back the temperature in real time
var App = Vue.component('App', {
template: "<h1> {{temperature}} </h1>",
data() {
return {
temperature: 0
};
},
created: function() {
this.fetchTemp('api/temperature');
setInterval(()=> {
this.fetchItems('api/temperature');
}, 500);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.temperature = res.data.temperature;
});
},
}
});
I tried to simulate your use case by getting the current time from REST API and show it every second
new Vue({
el: '#app',
data() {
return {
now: 0
};
},
created: function() {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
setInterval(() => {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
}, 1000);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.now = new Date(res.data.fulldate).toLocaleString();
}).catch(err => {});
}
}
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-axios@2.1.4/dist/vue-axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> Now : {{now}} </h1>
</div>
</body>
</html>
Thanks for answering me, go some problems to view the values using axios. Axios I installed it so npm install --save axios vue-axios. "<H1> {{temperature}} </ h1>" this tag prints me 0. It should not because your code says anything else.
– Salvatore Raccardi
Nov 12 at 17:02
@SalvatoreRaccardi i'm not familiar with Node.js but i gave you a basic example, the front end code is 100% correct , make sure thatlocalhost:8080/api/temperature
returns data
– Boussadjra Brahim
Nov 12 at 17:13
ok I solved now I see the temperature value on the html page. But it does not update automatically, as if axios or vue does not work properly. To view a new value I have to manually edit the page. Do you know how to help me?
– Salvatore Raccardi
Nov 12 at 21:50
please provide the new code i mean the vue js code
– Boussadjra Brahim
Nov 12 at 21:51
and the same you gave me
– Salvatore Raccardi
Nov 12 at 21:54
|
show 5 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Your code in backend should be like this :
//get the value from db
//create a variable tmp that will receives temperature from db
let tmp;
var router = express.Router();
router.get('/temperature', function(req, res) {
res.json({
temperature: tmp
});
});
app.use('/api', router);
in the front you have access to that api :
localhost:8080/api/temperature
And using axios you could make call to your backend and get back the temperature in real time
var App = Vue.component('App', {
template: "<h1> {{temperature}} </h1>",
data() {
return {
temperature: 0
};
},
created: function() {
this.fetchTemp('api/temperature');
setInterval(()=> {
this.fetchItems('api/temperature');
}, 500);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.temperature = res.data.temperature;
});
},
}
});
I tried to simulate your use case by getting the current time from REST API and show it every second
new Vue({
el: '#app',
data() {
return {
now: 0
};
},
created: function() {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
setInterval(() => {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
}, 1000);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.now = new Date(res.data.fulldate).toLocaleString();
}).catch(err => {});
}
}
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-axios@2.1.4/dist/vue-axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> Now : {{now}} </h1>
</div>
</body>
</html>
Thanks for answering me, go some problems to view the values using axios. Axios I installed it so npm install --save axios vue-axios. "<H1> {{temperature}} </ h1>" this tag prints me 0. It should not because your code says anything else.
– Salvatore Raccardi
Nov 12 at 17:02
@SalvatoreRaccardi i'm not familiar with Node.js but i gave you a basic example, the front end code is 100% correct , make sure thatlocalhost:8080/api/temperature
returns data
– Boussadjra Brahim
Nov 12 at 17:13
ok I solved now I see the temperature value on the html page. But it does not update automatically, as if axios or vue does not work properly. To view a new value I have to manually edit the page. Do you know how to help me?
– Salvatore Raccardi
Nov 12 at 21:50
please provide the new code i mean the vue js code
– Boussadjra Brahim
Nov 12 at 21:51
and the same you gave me
– Salvatore Raccardi
Nov 12 at 21:54
|
show 5 more comments
up vote
1
down vote
accepted
Your code in backend should be like this :
//get the value from db
//create a variable tmp that will receives temperature from db
let tmp;
var router = express.Router();
router.get('/temperature', function(req, res) {
res.json({
temperature: tmp
});
});
app.use('/api', router);
in the front you have access to that api :
localhost:8080/api/temperature
And using axios you could make call to your backend and get back the temperature in real time
var App = Vue.component('App', {
template: "<h1> {{temperature}} </h1>",
data() {
return {
temperature: 0
};
},
created: function() {
this.fetchTemp('api/temperature');
setInterval(()=> {
this.fetchItems('api/temperature');
}, 500);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.temperature = res.data.temperature;
});
},
}
});
I tried to simulate your use case by getting the current time from REST API and show it every second
new Vue({
el: '#app',
data() {
return {
now: 0
};
},
created: function() {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
setInterval(() => {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
}, 1000);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.now = new Date(res.data.fulldate).toLocaleString();
}).catch(err => {});
}
}
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-axios@2.1.4/dist/vue-axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> Now : {{now}} </h1>
</div>
</body>
</html>
Thanks for answering me, go some problems to view the values using axios. Axios I installed it so npm install --save axios vue-axios. "<H1> {{temperature}} </ h1>" this tag prints me 0. It should not because your code says anything else.
– Salvatore Raccardi
Nov 12 at 17:02
@SalvatoreRaccardi i'm not familiar with Node.js but i gave you a basic example, the front end code is 100% correct , make sure thatlocalhost:8080/api/temperature
returns data
– Boussadjra Brahim
Nov 12 at 17:13
ok I solved now I see the temperature value on the html page. But it does not update automatically, as if axios or vue does not work properly. To view a new value I have to manually edit the page. Do you know how to help me?
– Salvatore Raccardi
Nov 12 at 21:50
please provide the new code i mean the vue js code
– Boussadjra Brahim
Nov 12 at 21:51
and the same you gave me
– Salvatore Raccardi
Nov 12 at 21:54
|
show 5 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Your code in backend should be like this :
//get the value from db
//create a variable tmp that will receives temperature from db
let tmp;
var router = express.Router();
router.get('/temperature', function(req, res) {
res.json({
temperature: tmp
});
});
app.use('/api', router);
in the front you have access to that api :
localhost:8080/api/temperature
And using axios you could make call to your backend and get back the temperature in real time
var App = Vue.component('App', {
template: "<h1> {{temperature}} </h1>",
data() {
return {
temperature: 0
};
},
created: function() {
this.fetchTemp('api/temperature');
setInterval(()=> {
this.fetchItems('api/temperature');
}, 500);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.temperature = res.data.temperature;
});
},
}
});
I tried to simulate your use case by getting the current time from REST API and show it every second
new Vue({
el: '#app',
data() {
return {
now: 0
};
},
created: function() {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
setInterval(() => {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
}, 1000);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.now = new Date(res.data.fulldate).toLocaleString();
}).catch(err => {});
}
}
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-axios@2.1.4/dist/vue-axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> Now : {{now}} </h1>
</div>
</body>
</html>
Your code in backend should be like this :
//get the value from db
//create a variable tmp that will receives temperature from db
let tmp;
var router = express.Router();
router.get('/temperature', function(req, res) {
res.json({
temperature: tmp
});
});
app.use('/api', router);
in the front you have access to that api :
localhost:8080/api/temperature
And using axios you could make call to your backend and get back the temperature in real time
var App = Vue.component('App', {
template: "<h1> {{temperature}} </h1>",
data() {
return {
temperature: 0
};
},
created: function() {
this.fetchTemp('api/temperature');
setInterval(()=> {
this.fetchItems('api/temperature');
}, 500);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.temperature = res.data.temperature;
});
},
}
});
I tried to simulate your use case by getting the current time from REST API and show it every second
new Vue({
el: '#app',
data() {
return {
now: 0
};
},
created: function() {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
setInterval(() => {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
}, 1000);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.now = new Date(res.data.fulldate).toLocaleString();
}).catch(err => {});
}
}
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-axios@2.1.4/dist/vue-axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> Now : {{now}} </h1>
</div>
</body>
</html>
var App = Vue.component('App', {
template: "<h1> {{temperature}} </h1>",
data() {
return {
temperature: 0
};
},
created: function() {
this.fetchTemp('api/temperature');
setInterval(()=> {
this.fetchItems('api/temperature');
}, 500);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.temperature = res.data.temperature;
});
},
}
});
I tried to simulate your use case by getting the current time from REST API and show it every second
var App = Vue.component('App', {
template: "<h1> {{temperature}} </h1>",
data() {
return {
temperature: 0
};
},
created: function() {
this.fetchTemp('api/temperature');
setInterval(()=> {
this.fetchItems('api/temperature');
}, 500);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.temperature = res.data.temperature;
});
},
}
});
I tried to simulate your use case by getting the current time from REST API and show it every second
new Vue({
el: '#app',
data() {
return {
now: 0
};
},
created: function() {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
setInterval(() => {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
}, 1000);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.now = new Date(res.data.fulldate).toLocaleString();
}).catch(err => {});
}
}
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-axios@2.1.4/dist/vue-axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> Now : {{now}} </h1>
</div>
</body>
</html>
new Vue({
el: '#app',
data() {
return {
now: 0
};
},
created: function() {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
setInterval(() => {
this.fetchTemp('https://script.googleusercontent.com/a/macros/esi.dz/echo?user_content_key=ypoXRw1nVHj-h1VRDmh6TXSI1VpIPWW7Qo2n9El6RqoxAJ3v28nBI9bDY_4UAE0TQJ3pSozxpbTiRvFpmD8pvcTkGSnPAtgRm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_nRPgeZU6HP_B2BW4qWwVPUuHIcJ3mEdrfLIfNZsYUQi0c--vxV_3BX606CngcowlqSfFH8SSiqMPrUuXDMsd72r-P39_jlVDMh0BMLnMwXU02UuEHWiuob4ULL2SJgrtyBAf43AAwP8&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk');
}, 1000);
},
methods: {
fetchTemp(uri) {
axios.get(uri).then((res) => {
this.now = new Date(res.data.fulldate).toLocaleString();
}).catch(err => {});
}
}
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-axios@2.1.4/dist/vue-axios.min.js"></script>
</head>
<body>
<div id="app">
<h1> Now : {{now}} </h1>
</div>
</body>
</html>
edited Nov 13 at 1:33
answered Nov 11 at 16:13
Boussadjra Brahim
3,9832628
3,9832628
Thanks for answering me, go some problems to view the values using axios. Axios I installed it so npm install --save axios vue-axios. "<H1> {{temperature}} </ h1>" this tag prints me 0. It should not because your code says anything else.
– Salvatore Raccardi
Nov 12 at 17:02
@SalvatoreRaccardi i'm not familiar with Node.js but i gave you a basic example, the front end code is 100% correct , make sure thatlocalhost:8080/api/temperature
returns data
– Boussadjra Brahim
Nov 12 at 17:13
ok I solved now I see the temperature value on the html page. But it does not update automatically, as if axios or vue does not work properly. To view a new value I have to manually edit the page. Do you know how to help me?
– Salvatore Raccardi
Nov 12 at 21:50
please provide the new code i mean the vue js code
– Boussadjra Brahim
Nov 12 at 21:51
and the same you gave me
– Salvatore Raccardi
Nov 12 at 21:54
|
show 5 more comments
Thanks for answering me, go some problems to view the values using axios. Axios I installed it so npm install --save axios vue-axios. "<H1> {{temperature}} </ h1>" this tag prints me 0. It should not because your code says anything else.
– Salvatore Raccardi
Nov 12 at 17:02
@SalvatoreRaccardi i'm not familiar with Node.js but i gave you a basic example, the front end code is 100% correct , make sure thatlocalhost:8080/api/temperature
returns data
– Boussadjra Brahim
Nov 12 at 17:13
ok I solved now I see the temperature value on the html page. But it does not update automatically, as if axios or vue does not work properly. To view a new value I have to manually edit the page. Do you know how to help me?
– Salvatore Raccardi
Nov 12 at 21:50
please provide the new code i mean the vue js code
– Boussadjra Brahim
Nov 12 at 21:51
and the same you gave me
– Salvatore Raccardi
Nov 12 at 21:54
Thanks for answering me, go some problems to view the values using axios. Axios I installed it so npm install --save axios vue-axios. "<H1> {{temperature}} </ h1>" this tag prints me 0. It should not because your code says anything else.
– Salvatore Raccardi
Nov 12 at 17:02
Thanks for answering me, go some problems to view the values using axios. Axios I installed it so npm install --save axios vue-axios. "<H1> {{temperature}} </ h1>" this tag prints me 0. It should not because your code says anything else.
– Salvatore Raccardi
Nov 12 at 17:02
@SalvatoreRaccardi i'm not familiar with Node.js but i gave you a basic example, the front end code is 100% correct , make sure that
localhost:8080/api/temperature
returns data– Boussadjra Brahim
Nov 12 at 17:13
@SalvatoreRaccardi i'm not familiar with Node.js but i gave you a basic example, the front end code is 100% correct , make sure that
localhost:8080/api/temperature
returns data– Boussadjra Brahim
Nov 12 at 17:13
ok I solved now I see the temperature value on the html page. But it does not update automatically, as if axios or vue does not work properly. To view a new value I have to manually edit the page. Do you know how to help me?
– Salvatore Raccardi
Nov 12 at 21:50
ok I solved now I see the temperature value on the html page. But it does not update automatically, as if axios or vue does not work properly. To view a new value I have to manually edit the page. Do you know how to help me?
– Salvatore Raccardi
Nov 12 at 21:50
please provide the new code i mean the vue js code
– Boussadjra Brahim
Nov 12 at 21:51
please provide the new code i mean the vue js code
– Boussadjra Brahim
Nov 12 at 21:51
and the same you gave me
– Salvatore Raccardi
Nov 12 at 21:54
and the same you gave me
– Salvatore Raccardi
Nov 12 at 21:54
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249384%2fread-data-from-a-mongodb-database-using-vuejs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
did you make an API?
– Boussadjra Brahim
Nov 11 at 15:40