首页 > 解决方案 > 将 Vuex 数据从 API 传递到表

问题描述

因此,我的 HTML 中有一个 Bootstrap-Vue 表,我想将配方名称传递给我的字段。

我想加载数据recipeItems: []并将其传递给我的表。但我不断收到 null Id 作为错误响应。

...mapState({
    recipeName: (state) => state.recipe.name,
    recipeId: (state) => state.recipe.id
})

...mapActions({ 
fetchRecipe: "recipe/fetch"
      setId: "recipe/setId"
 })

mounted() {
   this.setId(this.recipeItems);
    this.fetchRecipe().then(() => {
      this.recipeItems = this.recipeName
      })
}
setId({ commit }, id) {
    commit(SET_ID, id);
},
fetch({ commit, state }) {
    return api.recipes.get(state.id).then(({ data }) => {
        commit(SET_NAME, data.name);
[SET_NAME](state, name) {
    state.name = name;
},
[SET_ID](state, id) {
      state.id = id;
    },

标签: vue.jsvuejs2vuex

解决方案


推荐阅读