问题
Hi i am using electron+vuejs and trying to receive data from electron's main process .That is some data is sent from main process to renderer process.And inside the renderer process i have ipcRenderer.on() in created() or mounted().But the data is not received there.And the text is not updated on the screen.My code is like shown below:Note even if i use mounted() it is not working .What am i doing wrong?How can i resolve this ?
<div>{{logText}}</div>
data(){
return {
logText:''
}
},
created(){
ipcRenderer.on('setlogText',(event,arg)=>{
console.log('logtext is: ',logText,"ended")
this.logText = arg;
console.log("setlogtext",arg);
})
}
回答1:
So i have solved the problem by using this.$nextTick().But now the problem is it updates on the next cycle not in the current one.So you can replace this.$nextTick with this.$watch and it will resolve the issue.For anyone reading coming across this in the future you can see the docs for $watch.Now there is another problem that ipcRendere.on() is called multiple times in the renderer process.How can i resolve this i don't know yet.
mounted:function(){
this.$nextTick(function(){
ipcRenderer.on('setlogText',(event,arg)=>{
this.logText = arg;
});
});
}
来源:https://stackoverflow.com/questions/64843605/text-is-not-changing-on-screen-when-using-ipcrenderer-on-inside-mounted-or-c