I am a beginner with Vue and I'm currently working on a project where I need to set a default value for Vue data return()
. Right now, when the code runs, it logs
console.log('INSIDE CLIENT ON MESSAGE")
. However, the value defined as this.room1status = 1
doesn't seem to be passed or updated in data return room1status
. Is there a way that I can assign the value of 1 to room1status
in Vue when inside client.on('message', function (topic, message)
?
Script
data(){
return{
room1status: ''
}
},
mounted: function(){
var mqtt = require('mqtt')
var client = mqtt.connect('ws://myUrl/')
client.on('connect', function () {
client.subscribe('route_status', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
var filterData = message;
var x = JSON.parse(filterData);
console.log('INSIDE CLIENT ON MESSAGE"); /** prints this out succesfully **/
this.room1status = 1; /** but this does not get passed or updated to data return room1status **/
}
}