手写vuex的mapGetters
Posted zhuxingqing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手写vuex的mapGetters相关的知识,希望对你有一定的参考价值。
<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>
以上是关于手写vuex的mapGetters的主要内容,如果未能解决你的问题,请参考以下文章