mapGetters
使用方式和mapState类似。在computed中:
import { mapGetters } from 'vuex'
computed:{
...mapGetters(["nameInfo","counterInfo"])
},
同样也有数组写法和对象写法。
在setup中使用mapGetters,也如同mapState一样需要进行一些处理:
import { computed } from 'vue'
import { mapGetters, useStore } from 'vuex'
export function useGetters(mapper){
const store = useStore();
const storeGettersFns = mapGetters(mapper);
const storeGetters = {}
Object.keys(storeGettersFns).forEach(fnKey=>{
const fn = storeGettersFns[fnKey].bind({$store: store});
storeGetters[fnKey]=computed(fn);
})
return storeGetters;
}
One thought on “VUE3之VUEX”
还差多少集看完啊