vuex当中mapmapMutations 使用

import { mapState,mapMutations  } from 'vuex';
//拿到多个方法
const mu=mapMutations(['changeName'])
export default {
  data () {
    return {
      
    }
  },
 methods: {
  ...mu, //注意导入
  changeNameFun(){
    // this.$store.commit('changeName','lisi')  //可直接调用
    this.changeName('lis'); //直接调用改变
  }
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: Vuex提供了一些辅助函数(mapState、mapActions、mapMutations),可以帮助我们在Vue组件中更方便地使用Vuex的状态管理功能。\[1\]这些辅助函数可以通过将Vuex.store中的属性映射到Vue实例中,使我们能够在Vue实例中直接访问Vuex.store中的属性,从而方便地操作Vuex.store。\[2\]使用辅助函数的方法是在Vue组件的computed属性和methods属性中使用这些辅助函数。例如,使用mapState辅助函数可以将Vuex.store中的状态映射到Vue组件的computed属性中,使用mapActions辅助函数可以将Vuex.store中的actions映射到Vue组件的methods属性中。\[3\]在使用辅助函数时,可以指定命名空间的路径来访问多个模块中的状态和操作。例如,使用mapState和mapActions辅助函数时,可以通过给定命名空间的路径来指定要映射的模块,并在Vue组件中使用这些映射后的方法。 #### 引用[.reference_title] - *1* *2* [vuex的辅助函数](https://blog.csdn.net/weixin_59519449/article/details/122134753)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [vuex中辅助函数的使用方法](https://blog.csdn.net/AkeDuan/article/details/123574487)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值