Text is not changing on screen when using ipcRenderer.on() inside mounted() OR created() VueJs+Electron

ぐ巨炮叔叔 提交于 2020-12-15 04:31:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!