鍍金池/ 問答/HTML/ 函數(shù)傳參的問題,vue里的小例子

函數(shù)傳參的問題,vue里的小例子

學(xué)習(xí)vue的vuex,官方例子中有一處看不懂

HTML

<div id="app">
  <p>{{ count }}</p>
  <p>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
  </p>
</div>

JS

const store = new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
      increment: state => state.count++,
    decrement: state => state.count--
  }
})

new Vue({
  el: '#app',
  computed: {
    count () {
        return store.state.count
    }
  },
  methods: {
    increment () {
      store.commit('increment')
    },
    decrement () {
        store.commit('decrement')
    }
  }
})

clipboard.png

如果要我自己去實(shí)現(xiàn),我會(huì)寫

mutations:{
    increment:function(){
        this.state.count++
    }
}
回答
編輯回答
綰青絲

看官網(wǎng)文檔https://vuex.vuejs.org/zh-cn/...
并且它會(huì)接受 state 作為第一個(gè)參數(shù)

2018年2月8日 23:20