Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重新加载页面时获取Nuxt.js_Javascript_Vue.js_Nuxtjs - Fatal编程技术网

Javascript 重新加载页面时获取Nuxt.js

Javascript 重新加载页面时获取Nuxt.js,javascript,vue.js,nuxtjs,Javascript,Vue.js,Nuxtjs,当使用nuxt.jsfetch()时,每当我重新加载页面时,它都不会再次获取它。除非我来自路由器链接。我如何强制它从我的API中重新蚀刻 导出默认值{ 异步获取(){ const data=wait this.$axios.$get(`/users/${this.$route.params.name}`) this.user=数据 }, 数据(){ 返回{ 用户:[] } } } 我看到的每一个页面,他们总是在页面刷新时显示占位符,而从他们的API中重新蚀刻,为什么我的Nuxt.js应用程序在

当使用nuxt.js
fetch()
时,每当我重新加载页面时,它都不会再次获取它。除非我来自路由器链接。我如何强制它从我的API中重新蚀刻

导出默认值{
异步获取(){
const data=wait this.$axios.$get(`/users/${this.$route.params.name}`)
this.user=数据
},
数据(){
返回{
用户:[]
}
}
}

我看到的每一个页面,他们总是在页面刷新时显示占位符,而从他们的API中重新蚀刻,为什么我的Nuxt.js应用程序在刷新时不这样做?它只是没有从我的API中重新读取数据,这很奇怪。

我相信,在Nuxt.JS中,fetch方法仅在从路由器导航渲染时调用-手动重新加载不会触发此操作

也许您可以使用
beforeMount()
而不是
fetch()
构造一个mixin,并将其应用于需要它的页面

当然,也可以只在页面上:

async beforeMount() {
    const data = await this.$axios.$get(`/users/${this.$route.params.name}`)
    this.user = data
},

刚刚遇到了同样的问题

在fetch上浏览Nuxt文档后,似乎将fetchOnServer选项设置为false会在客户端和页面重新加载(服务器端)时触发fetch钩子,从而解决了以下问题:

fetchOnServer: false

那么,使用fetch到底有什么意义呢?