如何使用 rest API 在应用程序启动时正确初始化 Vuex 存储?
How to properly initialize Vuex store on app startup using rest API?
我想用从 API 获取的一些数据初始化商店(我使用的是 axios)如何在应用程序启动时执行此操作,仅一次?
我有一个导出我的商店的 store.js 文件和一个执行此操作的 main.js 文件:
import Vue from "nativescript-vue";
import store from "./store";
new Vue({
store,
render: (h) => h("frame", [h(App)]),
}).$start();
尝试将 .dispatch()
与您的 Axios REST API 抓取功能一起使用在主 Vue 组件(您包含存储的组件)的 created()
挂钩中:
new Vue({
store,
render: (h) => h("frame", [h(App)]),
created() {
this.$store.dispatch('myAxiosFetchFunction');
},
}).$start();
我想用从 API 获取的一些数据初始化商店(我使用的是 axios)如何在应用程序启动时执行此操作,仅一次?
我有一个导出我的商店的 store.js 文件和一个执行此操作的 main.js 文件:
import Vue from "nativescript-vue";
import store from "./store";
new Vue({
store,
render: (h) => h("frame", [h(App)]),
}).$start();
尝试将 .dispatch()
与您的 Axios REST API 抓取功能一起使用在主 Vue 组件(您包含存储的组件)的 created()
挂钩中:
new Vue({
store,
render: (h) => h("frame", [h(App)]),
created() {
this.$store.dispatch('myAxiosFetchFunction');
},
}).$start();