Vuex If 语句检查 asyncData 中的 store.state 值
Vuex If statement check store.state value in asyncData
我必须在 asyncData 中使用 if 语句。
asyncData(context) {
if (dataType === 'individual') {
return fetchPageData(context, 'dashboard');
} else {
return fetchPageData(context, 'dashboardCompany');
}
},
computed: {
...mapState({
dataType: (state) => state.user.user.type,
}),
},
此代码给我一个“错误 'dataType' 未定义 no-undef”
当我在 asyncData 中尝试 this.dataType 时,我得到“错误 Unexpected this in asyncData nuxt/no-this-in-fetch-data”
fetchPageData 是 axions.get 的插件。json 带有数据的文件。
任何solution/hint?
您不能在 asyncData 上使用计算 属性。
如果您想使用“store”,store 包含在 asyncData 上下文中。
我必须在 asyncData 中使用 if 语句。
asyncData(context) {
if (dataType === 'individual') {
return fetchPageData(context, 'dashboard');
} else {
return fetchPageData(context, 'dashboardCompany');
}
},
computed: {
...mapState({
dataType: (state) => state.user.user.type,
}),
},
此代码给我一个“错误 'dataType' 未定义 no-undef” 当我在 asyncData 中尝试 this.dataType 时,我得到“错误 Unexpected this in asyncData nuxt/no-this-in-fetch-data”
fetchPageData 是 axions.get 的插件。json 带有数据的文件。
任何solution/hint?
您不能在 asyncData 上使用计算 属性。
如果您想使用“store”,store 包含在 asyncData 上下文中。