<script>
????import?store?from?'@/store'
????export?default?{
????????name:?"Add",
????????store,
????????data()?{
????????????return?{
????????????????title:?'',
????????????????content:?''
????????????}
????????},
????????methods:?{
????????????add()?{
????????????????store.commit('addItem',?{
????????????????????title:?this.title,
????????????????????content:?this.content
????????????????})
????????????}
????????}
????};
</script>
export?default?new?Vuex.Store({
??state:?{
????lists:?[]
??},
??mutations:?{
????addItem(state,add)?{
??????state.lists.push(add)
????}
},
2019-08-15
同學有沒有使用dev-tools去看看當點擊的時候,有沒有產生commit的事件?
打幾個斷點,加debugger看看,然后打開調試窗口
在console里面看看有沒有報錯。
從上面的代碼看,也沒有看到你的截圖,你的add方法寫的沒有問題