我试图将参数传递到我的路线,但当它到达我的商店时action,它给了我undefined错误!
我尝试更改参数名称,也尝试将其放入$route.params.id方法中并从那里调用它,但仍然没有效果!
<router-link to="/menu/add/1" tag="h2" class="pull-right">Add Menu</router-link>
Run Code Online (Sandbox Code Playgroud)
methods: {
...mapActions(['addMenu']),
addMenuItem() {
this.addMenu(this.menu, this.$route.params.typeId);
}
}
Run Code Online (Sandbox Code Playgroud)
{ path: '/menu/add/:typeId', component: MenuAdd }
Run Code Online (Sandbox Code Playgroud)
state: {
menu: [],
breakfastMenu: [],
lunchMenu: [],
dinnerMenu: []
}
Run Code Online (Sandbox Code Playgroud)
addMenu: ({ commit }, { name, price, description }, typeId) => {
commit('ADD_MENU', { name, price, description }, typeId);
alert('Menu Successfully Added');
}
Run Code Online (Sandbox Code Playgroud)
'ADD_MENU': (state, { name, price, description }, typeId) => {
state.menu.forEach((element) …Run Code Online (Sandbox Code Playgroud)