mount () 또는 created () VueJs + Electron 내부에서 ipcRenderer.on ()을 사용할 때 화면에서 텍스트가 변경되지 않습니다.

Nov 15 2020

안녕하세요 저는 electron + vuejs를 사용하고 있으며 electron의 주 프로세스에서 데이터를 수신하려고합니다. 즉, 일부 데이터는 주 프로세스에서 렌더러 프로세스로 전송됩니다. 렌더러 프로세스 내부에는 created () 또는 mount ()에 ipcRenderer.on ()이 있습니다. . 그러나 거기에 데이터가 수신되지 않고 화면에 텍스트가 업데이트되지 않습니다. 내 코드는 아래와 같습니다 .mounted ()를 사용하더라도 작동하지 않습니다. 무엇을 잘못하고 있습니까? 어떻게 해결할 수 있습니까? ?

<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);
        })
    }

답변

JasonLiam Nov 15 2020 at 13:14

그래서 이것을 사용하여 문제를 해결했습니다.$nextTick().But now the problem is it updates on the next cycle not in the current one.So you can replace this.$nextTick.$watch and it will resolve the issue.For anyone reading coming across this in the future you can see the docs for $이제 렌더러 프로세스에서 ipcRendere.on ()이 여러 번 호출되는 또 다른 문제가 있습니다. 아직 모르는 문제를 어떻게 해결할 수 있습니까?

mounted:function(){         
            this.$nextTick(function(){
                ipcRenderer.on('setlogText',(event,arg)=>{
                    this.logText = arg;
                });
            });
        }