Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 来自VUEX存储的Axios请求_Javascript_Vue.js_Nuxt.js - Fatal编程技术网

Javascript 来自VUEX存储的Axios请求

Javascript 来自VUEX存储的Axios请求,javascript,vue.js,nuxt.js,Javascript,Vue.js,Nuxt.js,正在从VUEX存储设备向服务器发送数据: (类似这样的内容) 这在vue.js(nuxt.js)开发社区中是正常的吗?) 这种做法是否可以接受在Vuejs中,如果将Vuex用作常规存储,则可以在Vuex模块的“操作”部分写入请求。有关构建Vuex商店的更多信息,请查看链接 在Vuex模块中设置状态和getter const state = { ... }; const getters = { ... }; 在actions对象中添加用于请求服务器的代码 const actions =

正在从
VUEX
存储设备向服务器发送数据:
(类似这样的内容)

这在vue.js(nuxt.js)开发社区中是正常的吗?)

这种做法是否可以接受

在Vuejs中,如果将Vuex用作常规存储,则可以在Vuex模块的“操作”部分写入请求。有关构建Vuex商店的更多信息,请查看链接

在Vuex模块中设置状态和getter

const state = {
  ...
};

const getters = {
  ...
};
在actions对象中添加用于请求服务器的代码

const actions = {
  async setTrackData({ commit }, value) {
    try {
       const res = await axios.get("https://seo-gmbh.eu/invest/input.php");
       commit("SET_TO_THE_FINAL_DESTINATION", value);
       ...
    } catch (error) {
       ...
    }
  },
};
如果要通过操作更改Vuex的状态,请通过突变对象中的突变函数提交更改

const mutations = {
  /* set the data to the state value from the state object */
  SET_TO_FINAL_DESTINATION(state, data) {
    ...
  },
};
最后,要使用Vuex存储操作和getter,必须在computed部分导入getter,并在methods对象的开头导入操作。举个例子,

export default Vue.component('ABC', {
  ...
    computed: {

    ...mapGetters([
      /* import the getters here */
      'getSomeState',
    ]),
  },
  ...
  methods: {
  ...mapActions([
     /* import the actions here */
     'setTrackData',
  ]),
  ...
  }
}

要进一步构造Vuejs项目中的API调用,请在Vuejs中签出此链接。如果您将Vuex用作常规存储,则可以在Vuex模块的“操作”部分编写请求。有关构建Vuex商店的更多信息,请查看链接

在Vuex模块中设置状态和getter

const state = {
  ...
};

const getters = {
  ...
};
在actions对象中添加用于请求服务器的代码

const actions = {
  async setTrackData({ commit }, value) {
    try {
       const res = await axios.get("https://seo-gmbh.eu/invest/input.php");
       commit("SET_TO_THE_FINAL_DESTINATION", value);
       ...
    } catch (error) {
       ...
    }
  },
};
如果要通过操作更改Vuex的状态,请通过突变对象中的突变函数提交更改

const mutations = {
  /* set the data to the state value from the state object */
  SET_TO_FINAL_DESTINATION(state, data) {
    ...
  },
};
最后,要使用Vuex存储操作和getter,必须在computed部分导入getter,并在methods对象的开头导入操作。举个例子,

export default Vue.component('ABC', {
  ...
    computed: {

    ...mapGetters([
      /* import the getters here */
      'getSomeState',
    ]),
  },
  ...
  methods: {
  ...mapActions([
     /* import the actions here */
     'setTrackData',
  ]),
  ...
  }
}
要在Vuejs项目中进一步构造API调用,请签出此链接