vue.js - 在 nuxtServerInit() 中使用 Axios
问题描述
我需要让远程数据显示在每个页面中。
此调用在以下位置执行store/index.js
:
export const state = () => ({
contact: {
hello: "World"
}
});
export const actions = {
async nuxtServerInit({ commit, state }) {
const { contactData } = await this.$axios.get("/contact");
commit("SET_CONTACT", contactData);
}
};
export const mutations = {
SET_CONTACT(state, contactData) {
state.contact = contactData;
}
};
问题是store中的contact
turns的值undefined
,而预期的内容是通过axios检索的(检索到的内容显示在SSR控制台...)
我在这里想念什么?
解决方案
推荐阅读
- flutter - 将切换按钮展开到父容器宽度
- react-native - 如何在反应原生导航中从父屏幕调用子(选项卡)屏幕内的功能
- vue.js - 在 Vue.js 应用程序中,PhpStorm IDE 中有很多错误
- c# - 为什么调用 Tesseract 进程会导致该服务随机崩溃?
- python-3.x - python-rq 工作人员是否支持多处理模块?
- android - 如何防止导航器推送刷新屏幕
- python - 逐行移动数组中的元素并移动其他元素?
- keras - 在 keras 中使用 EfficientNet 时出现 ResourceExhaustedError
- java - SparkJava awaitStop() 方法立即返回,即使在初始化之后,但 stop() 还没有被调用
- algorithm - 这个解决方案的算法复杂度是多少?