Plugins 直接命中链接时无法获取存储值
在不访问主页的情况下点击网站链接并不是在商店中设置值 我在nuxtServerInit操作中进行了axios调用,并在中设置了数据。我现在可以在项目中的任何地方访问这些数据,但是如果我从网站加载了一个特定的页面,那么在刷新之前数据不会显示 下面是Plugins 直接命中链接时无法获取存储值,plugins,google-analytics,url-routing,store,nuxt.js,Plugins,Google Analytics,Url Routing,Store,Nuxt.js,在不访问主页的情况下点击网站链接并不是在商店中设置值 我在nuxtServerInit操作中进行了axios调用,并在中设置了数据。我现在可以在项目中的任何地方访问这些数据,但是如果我从网站加载了一个特定的页面,那么在刷新之前数据不会显示 下面是store/index.js文件 /* eslint-disable */ import Vuex from 'vuex' import axios from 'axios' const createStore = () => { retur
store/index.js
文件
/* eslint-disable */
import Vuex from 'vuex'
import axios from 'axios'
const createStore = () => {
return new Vuex.Store({
state: {
organisation: Object,
},
mutations: {
setOrganisation(state, organisation){
state.organisation = organisation
},
},
actions: {
nuxtServerInit({ commit }, context){
axios.get(api-link-to-fetch-data-from-backend))
.then(res => {
commit("setOrganisation", res.data[0])
})
.catch(e => context.error(e));
}
},
getters: {
getOrganisation(state){
return state.organisation;
}
}
})
}
此数据需要在导航栏中使用。因此它是从layout/default.vue的created方法中的存储中获取的,如下所示
created() {
this.organisation = this.$store.getters.getOrganisation;
}
由于nuxtServerInit是nuxt生命周期中调用的第一个函数,为什么直接访问网站的任何链接时都不存储数据
示例如下:
刷新页面后,将设置有关最近视频的此信息