getter 帶參數
參考: https://vuex.vuejs.org/guide/getters.html#method-style-access
或者: https://stackoverflow.com/questions/37763828/javascript-es6-double-arrow-functions
官方例子:
getters: { // ... getTodoById: (state) => (id) => { return state.todos.find(todo => todo.id === id) }}使用:
store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }stackoverflow 例子:
new Vuex.Store({ getters: { someMethod(state){ var self = this; return function (args) { // return data from store with query on args and self as this }; } }})commit 帶參數
參考; https://stackoverflow.com/questions/46097687/vuex-passing-multiple-parameters-to-action 和 https://stackoverflow.com/questions/40522634/can-i-pass-parameters-in-computed-properties-in-vue-js
就是把第二個參數,以hash的形式傳過來。
// vue頁面調用: store.commit(INCREASE, { vid: vid // 這里可以容納更多參數 })// store.js const mutations = { [INCREASE](state, data){ pair = state.pairs.find( (pair) => { return pair.vid == data.vid // 注意這里的 data.vid 就是了。 }) }}以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。
新聞熱點
疑難解答
圖片精選