// 因为axios异步,此时response.data仍然是空的
// 请问如何同步,等axios resolve 再返回 response.data
// background-script.js
browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
let response
axios({
...
}).then(
a => {
// 异步得到response
response = a
}
)
// 因为axios异步,此时response.data仍然是空的
// 请问如何同步,等axios resolve 再返回 response.data
return Promise.resolve(response.data)
})
//content-script.js
browser.runtime.sendMessage('message').then(
data => {
...
},
error => console.log(`Error: ${error}`))
|
|