const getters = {style:state => state.style}
computed: {
doneTodosCount () {
return this.$store.getters.doneTodosCount}
import { mapGetters } from 'vuex'
computed: {
// 使用对象展开运算符将 getters 混入 computed 对象中
...mapGetters([
'doneTodosCount',
'anotherGetter',])}
//给getter属性换名字
mapGetters({
// 映射 this.doneCount 为 store.getters.doneTodosCount
doneCount: 'doneTodosCount'
})
function `wrapGetters` (store, moduleGetters, modulePath) {
Object.keys(moduleGetters).forEach(getterKey => {
// 遍历先所有的getters
const rawGetter = moduleGetters[getterKey]
if (store._wrappedGetters[getterKey]) {
console.error(`[vuex] duplicate getter key: ${getterKey}`)
// getter的key不允许重复,否则会报错
return
}
store._wrappedGetters[getterKey] = function `wrappedGetter` (store{
// 将每一个getter包装成一个方法,并且添加到store._wrappedGetters对象中,
return rawGetter(
//执行getter的回调函数,传入三个参数,(local state,store getters,rootState)
getNestedState(store.state, modulePath), // local state
//根据path查找state上嵌套的state
store.getters,
// store上所有的getters
store.state
// root state)}})
}
//根据path查找state上嵌套的state
function `getNestedState` (state, path) {
return path.length
? path.reduce((state, key) => state[key], state): state}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有