vue.js - 将 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;
},
解决方案
推荐阅读
- mamp - MAMP - 单击“启动服务器”后收到错误请求
- qt - Qml FolderListModel 无法访问共享文件夹
- powershell - PowerShell IComparable 与子类
- neo4j - 在 Neo4j 中查询不存在的标签时,MyBatis 映射器永远不会返回
- flask - 烧瓶登录重定向回登录页面
- node.js - 在 AWS Lambda 中共享代码
- c# - 使用 Where 谓词过滤 detail.List 与另一个列表
- phonegap - PhoneGap:如何在 index.html 启动之前删除 Hello 字屏幕
- php - 如何循环通过 3 维数组将数据插入数据库?
- amazon-web-services - 我的 AWS Elastic Beanstalk 应用程序消失了