vuex中函数用法汇总

<div>
    <p>1.如何全局使用state</p>
    <span>{{this.$store.state.xxx }}</span>
    computed:{ 
        ...mapState(['xxx']) 
        ...mapState({新名字:'xxx'})
    }

    <p>2.如何使用modules中的state</p>
    <span>{{ this.$store.state.模块名.xxx }}</span>
    computed:{ 
        ...mapState('模块名',['xxx']) 
        ...mapState('模块名',{新名字:'xxx'})
    }

    <p>3.是个使用全局getters</p>
    <span>{{ this.$store.getters.xxx }}</span>
    computed:{
        ...mapGetters(['xxx'])
        ...mapGetters({'新名字':'xxx'})
    }

    <p>4.如何使用modules中的getters</p>
    <span>{{ this.$store.getters.模块名.xxx }}</span>
       computed:{
        ...mapGetters('模块名',['xxx'])
        ...mapGetters('模块名',{'新名字':'xxx'})
    }

    <p>5.如何使用全局中的mutations</p>
    <span>{{ this.$store.commit("mutation名", 参数) }}</span>
    methods:{
        ...mapMutations(['mutation名字'])
        ...mapMutations({'新名字':'motations名'})
    }

    <p>6.如何使用modules中的mutations(namespaced:true)</p>
    <span>{{ this.$store.commit("模块名/mutation名",参数) }}</span>
        methods:{
        ...mapMutations('模块名',['motations名'])
        ...mapMutations('模块名',{'新名字':'motations名'})
    }

    <p>7.如何使用全局actions</p>
    <span>{{ this.$store.dispatch("actions名", 参数) }}</span>
      methods:{
        ...mapActions(['actions名字'])
        ...mapActions({'新名字':'actions名'})
    }

    <p>8.如何使用modules中的actions</p>
    <span>{{ this.$store.dispatch("模块名/action名",参数) }}</span>
      methods:{
        ...mapActions(['模块名',['action名'])
        ...mapActions('模块名',{'新名字':'actions名'})
    }
  </div>

  • 7
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值