简体   繁体   English

如何在popup.js和background.js之间传递正确的消息?

[英]How to do correct message passing between popup.js and background.js?

My extension should work like this: Some data send from popup.js to background.js, in background.js I work with some web api services. 我的扩展应该这样工作:一些数据从popup.js发送到background.js,在background.js我使用一些web api服务。 And after that I send new data from background.js to popup.js for show in popup.html. 之后,我将来自background.js的新数据发送到popup.js,以便在popup.html中显示。

But if I after send from popup.js to background.js I close and open popup.html than data from background.js can't get popup.js because port doesn't exist. 但是如果我从popup.js发送到background.js后我关闭并打开popup.html而不是来自background.js的数据无法获得popup.js因为端口不存在。

I tried use localstorage. 我尝试过使用localstorage。 But my popup.html write on Vue and localsorage for Vue is not react and my data don't updates in popup.html if my popup.html was not closed/open. 但是如果我的popup.html没有关闭/打开,我的popup.html写在Vue和localsorage上的Vue没有反应,我的数据不会在popup.html中更新。

How to do correct message passing? 如何正确传递消息?

You are looking for VueX, which role is to store data for all the application. 您正在寻找VueX,其角色是存储所有应用程序的数据。

https://vuex.vuejs.org/ https://vuex.vuejs.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM