关于vuex
state:{ count:0 }
// 原始形式调用时插值表达式形式
<div>{{$store.state.count}}</div>
赋值函数形式是在computed中
important {mapStatte} from'vuex'
computed:{
...mapState['count']
count(){
return:this.$store.state.count
}
}
1 // 修改state 2 mutations:{
// es5
// addcount:function(){}
// es6
// state指的是当前vuex中的state对象
// payload 载荷提交mutation时传递的参数 3 addCount(state,payload){ 4 state.count += payload 5 } 6 }
// 直接调用形式
this.$store.commit('addCount',10)
// 辅助函数形式 在methods中调用mapMutations
important {} from 'vuex'
methods:{
// addCount(){
// this.$store.commit('addCount')
// }
...mapMatations['addcount'] // 此时方法中就会有一个对应的addCount方法
}
// action 异步动作 actions:{ // action 参数 context 相当于 组件中的this.$store stroe的运行实例 getAsyncCount(){ // 模拟异步请求 setTimeout(()=>{ context.commit('addCount',123) },1000) } } // 原始形式调用action // diapatch 调用action // dispatch(action名称,传递参数) this.$store.dispatch('getAsyncCount') // 辅助函数调用 important mapActions(['getAsynCount']) methods:{ ...mapActions(['getAsynCount']) // 相当于在方法中有一个getAsynCount }
getters:{ // 放置所有的vuex的计算属性 // state 指的就是当前store中的state // es5 // filterList:function(state){ // state.list.filter(item =>item>5) // } // es6 写法 filterList:state => state.list.filter(item =>item>5) } 原始调用形似 <div>{{$store.getters.filterList}}</div> 辅助函数形式---mapGetters important {mapGetters} from 'vuex' computed:{ ...mapGetters(['filterList']) }
// 模块化
读取子模块的state

// 命名空间 nameSpaced



【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南