问题描述
我不确定为什么,但是当我尝试在前端的浏览器扩展中发送响应时,我在控制台中得到一个空的响应对象。我正在使用vue和polyfill创建它,使其可以在Firefox和chrome上运行。这是代码:
background.js
import nedb from "nedb-promises";
const db = {};
let storedSettings = {};
db.settings = nedb.create({
autoload: true,filename: browser.runtime.getURL("settings.db")
});
browser.runtime.onMessage.addListener( async (message,sender,sendResponse) => {
console.log(message);
if( message.action === "readSettings" ){
readSettings();
console.log(storedSettings); // here the variable is defined and contains the info to send
return new Promise( (resolve) => {
console.log(storedSettings); // also here the variable contains the info to send
resolve(storedSettings)
});
}
});
popup.js vue组件
export default {
name: 'Popup',data() {
return {
proxyActive: false
}
},created() {
browser.runtime.sendMessage({action: "readSettings"}).then( (response) => {
console.log(response); // the response is empty
});
},mounted() {
},computed: {
},methods: {
}
}
我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)