【问题标题】:Refresh statically generated page (data) once it has loaded on client加载到客户端后刷新静态生成的页面(数据)
【发布时间】:2020-09-27 20:38:56
【问题描述】:

例如我在 Nuxt 有一些页面:

data() {
        return {
            items: []
        };
    },
    asyncData() {
        return axios.get('site.com/url')
            .then((response) => {
                return {
                    items: response.data
                };
            });
    },

然后我运行 npm run generate 并从后端服务器获取静态生成的带有数据(项目)的 html 页面。当我在浏览器中打开此页面时,我看到将数据注入到页面中。

但是这些项目可能会在后端更新,所以我需要在使用 F5 刷新页面并且不再运行 npm run generate 后查看它们。

看来我应该在mounted() 部分重新获取数据。也许 Nuxt 有更适合这个的东西?

【问题讨论】:

    标签: vue.js nuxt.js


    【解决方案1】:

    唯一的选择是在nuxt.config.js 文件中使用crawler: false 属性。它将禁用从您的动态页面生成静态内容。这是documentation

    【讨论】:

      猜你喜欢
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      相关资源
      最近更新 更多