getter方法的作用 vuex_vuex中getter的用法

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-29 15:36   11   0

在vuex中getter相当于计算属性

1.在store.js中写上:

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({

state:{

count:0,

},

mutations:{

changeCount:function (state,count) {

state.count=count

console.log(state.count)

},

getters: {

// 单个参数

countDouble: function(state){

return state.count * 2

},

// 两个参数

CountDoubleAndDouble: function(state, getters) {

return getters.countDouble * 2

}

}

})

2.在组件的页面写:(这里调用的方式有两种)

第一种:

一个参数:{{countDouble}}

两个参数{{CountDoubleAndDouble}}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP