国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

如何為vuex實現帶參數的 getter和state.commit

2024-05-06 15:43:34
字體:
來源:轉載
供稿:網友

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 就是了。  }) }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 融水| 九台市| 密山市| 新田县| 成武县| 桃园市| 盐山县| 运城市| 乌鲁木齐市| 东方市| 来安县| 十堰市| 深州市| 东台市| 来凤县| 东丽区| 平和县| 儋州市| 射阳县| 尚志市| 锡林郭勒盟| 安顺市| 随州市| 西青区| 玛纳斯县| 都兰县| 精河县| 金堂县| 砀山县| 得荣县| 星座| 舞阳县| 泽普县| 仁布县| 山西省| 科尔| 安图县| 万盛区| 名山县| 新昌县| 青龙|