标签:reac for his dispatch getters compute foreach exp default
<script> import { mapGetters } from ‘vuex‘ const getters = { a: () => 1, b: () => 2 } function fn (keys) { const data = {} keys.forEach(key => { // if (getters.hasOwnProperty(key)) { if (Object.prototype.hasOwnProperty.call(getters, key)) { data[key] = getters[key] } }) return data } export default { computed: { ...mapGetters([‘test‘]), ...fn([‘a‘, ‘b‘, ‘c‘]) }, mounted () { this.$store.dispatch(‘setTest‘, 9).then(() => { console.log(this.test) console.log(this.a, this.b, this.c) }) } } </script>
标签:reac for his dispatch getters compute foreach exp default
原文地址:https://www.cnblogs.com/zhuxingqing/p/13124309.html