我正在尝试使用Vue在一个非常简单的示例应用程序中使用WorkBox进行后台同步请求。我修改了很长时间的代码,但没有找到解决方案,或者也许是我的代码有问题。
服务工作者已正确注册,当我发出ajax请求时,后台同步已激活。
VUE
<template>
<div class="users">
<h1>USERS</h1>
<input type="text" v-model="qty" placeholder="How many users to find">
<button @click.prevent="search()">How many users would you like to find?</button>
<ul>
<li v-for="user in users">
{{user.email}}
</li>
</ul>
</div>
</template>
<script>
import axios from 'axios'
export default {
data(){
return {
users: null,
qty: 10
}
},
methods:{
search(){
axios.get('https://randomuser.me/api', {
params: {
results: this.qty
}
})
.then(response => {
console.log(response);
this.users = response.data.results
})
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
VUE.CONFIG.JS
module.exports = {
// ...other vue-cli plugin options...
pwa: {
name: 'My App',
themeColor: '#4DBA87',
msTileColor: '#000000',
appleMobileWebAppCapable: 'yes',
appleMobileWebAppStatusBarStyle: 'black',
workboxPluginMode: 'GenerateSW',
workboxOptions: {
runtimeCaching: [{
urlPattern: new RegExp('https://randomuser.me/api'),
handler: 'networkOnly',
options: {
//background sync. conf
backgroundSync: {
name: 'my-queue-asier',
options: {
maxRetentionTime: 60 * 60,
}
}
}
}]
}
}
}
这些是触发事件时来自DevTools的屏幕截图。
background-sync is registered in indexDB tab
有人可以帮助我吗?我正在寻找,但没有找到任何东西...
谢谢!