Read data from a mongodb database using vuejs












1














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>












share|improve this question






















  • did you make an API?
    – Boussadjra Brahim
    Nov 11 at 15:40
















1














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>












share|improve this question






















  • did you make an API?
    – Boussadjra Brahim
    Nov 11 at 15:40














1












1








1


1





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>












share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 13:48









Salvatore Raccardi

157




157












  • 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




did you make an API?
– Boussadjra Brahim
Nov 11 at 15:40












1 Answer
1






active

oldest

votes


















1














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>








share|improve this answer























  • 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










  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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>








share|improve this answer























  • 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










  • 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
















1














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>








share|improve this answer























  • 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










  • 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














1












1








1






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>








share|improve this answer














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>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 at 1:33

























answered Nov 11 at 16:13









Boussadjra Brahim

5,0373631




5,0373631












  • 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










  • 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










  • @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










  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini