<li v-for="(value, key) in iPhone6S.style" @click="changeStyle(key)" :class="{active: iPhone6S.activeStyleUrl == value}"> <span v-text="key"></span> </li>mutations.js: const state = { iPhone6S: { name: 'Apple/蘋果 iPhone 6S', desc: '3D Touch、1200萬像素照片、4k視頻,強(qiáng)大功能于一身。', price: '5288 - 6888', isSelected: true, style: { '玫瑰金色': 'http://o8yu724qs.bkt.clouddn.com/iphone6s-rosegold-select-2015.png' }, activeStyleUrl: 'http://o8yu724qs.bkt.clouddn.com/iphone6s-silver-select-2015.png', storage: { '16GB': 5288, '64GB': 6088, '128GB': 6888 } }, cart: []} actions.js import * as types from './types'export default { changeStyle: ({ commit }) => { commit(types.CHANGESTYLE) }}types.jsexport const CHANGESTYLE = 'CHANGESTYLE'問題是alert可以彈出來,為什么styleKey 是undefined,還有為什么CHANGESTYLE事件 默認(rèn)的參數(shù)是state
2 回答

BIG陽
TA貢獻(xiàn)1859條經(jīng)驗 獲得超6個贊
mutations 回調(diào)傳入的兩個參數(shù)第一個是state 也就是你當(dāng)前modules的state, 第二個參數(shù)是你dispatch或者在action中commit的中傳入的第二個參數(shù)。 你這邊styleKey顯示是undefined 應(yīng)該是你在dispatch或者你在action中的commit沒有傳值
添加回答
舉報
0/150
提交
取消