programing

rest API를 사용하여 앱 부팅 시 Vuex 스토어를 올바르게 초기화하려면 어떻게 해야 합니까?

goodcopy 2022. 8. 12. 00:22
반응형

rest API를 사용하여 앱 부팅 시 Vuex 스토어를 올바르게 초기화하려면 어떻게 해야 합니까?

API에서 가져온 데이터를 사용하여 스토어를 초기화합니다(액시스를 사용하고 있습니다).앱 부팅 시 한 번만 어떻게 해야 하나요?

스토어를 내보내는 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 하여 Axios REST API를 합니다.created()Vue(Vue) :

new Vue({
  store,
  render: (h) => h("frame", [h(App)]),
  created() {
    this.$store.dispatch('myAxiosFetchFunction');
  },
}).$start();

언급URL : https://stackoverflow.com/questions/57249465/how-to-properly-initialize-vuex-store-on-app-startup-using-rest-api

반응형