NuxtJS/Vue 在挂载后更新页面数据



我有一个HTTP请求,在挂载后调用

mounted: function() {
    return axios.get('/api/user/profile/stats')
        .then((res) => {
            console.log(res)
            return {
                stats: res
            }
        })
        .catch((e) => {
            console.log(e)
        })
}

但是一旦完成,页面就不会更新在哪里

<h2 class="text-green" v-if="stats" data-plugin="counterup">{{stats.ident}}</h2>

请求成功后,如何重新加载数据

要修改组件数据,您需要分配给 this.stats,以便它在其他地方可用。在装载中返回不会为您提供任何内容,因为返回值不会在任何地方使用。

如果你在浏览器中使用 Vue devtools,在检查组件数据时也很容易看到 stats 属性实际上并没有改变。

最新更新