zoukankan      html  css  js  c++  java
  • 关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(一)-----mapState

    一、通过mapState函数的对象参数来赋值:

    <p>{{ count }}</p>
    <p>{{ count1 }}</p>
    <p>{{ count2 }}<p>
    //导入
    import { mapState } from 'vuex'
    export default {
        data() {
            return {
                msg: 'vuex理解要点',
                id: 1
            }
        },
        store,
        //方法二:通过mapState对象来赋值
        computed: mapState({
            //使用箭头函数
            count: state => state.count,
            //传入字符串 ‘count’ 等同于 `state => state.count`
            count1: 'count',
            // 为了能够使用 `this` 获取局部状态,必须使用常规函数
            count2(state) {
                return state.count + this.id
            }
        })
    }
    三、通过mapState函数的数组参数来赋值
    当映射的计算属性的名称与 state 的子节点名称相同时,我们也可以给 mapState 传一个字符串数组。
    // 映射 this.count 为 store.state.count
    computed:mapState(['count'])
  • 相关阅读:
    深度学习面试问题
    重新学习pytorch的库函数等..
    新电脑的操作系统win10的所有设置问题汇总
    二叉搜索树,和红黑树,
    Most common words
    Word histogram
    Random numbers
    Word frequency analysis
    DSU
    Sequences of sequences
  • 原文地址:https://www.cnblogs.com/lhl66/p/8261690.html
Copyright © 2011-2022 走看看