当前位置: 首页 > 工具软件 > store.js > 使用案例 >

vue 获取及修改store.js里的公共变量

海宁
2023-12-01
<input type='text' :value='newVal'>
<button @click='edit'> 修改 </botton>
data(){
 return{
   newVal:''
 }
},
methods:{
  edit(newVal){
   this.$store.commit('edit',newVal)
 }
},
computed:{
//读取store中的属性
	 userid:function(){
	 	 return this.$store.state.userId
	 }
}
state: {
 userId:''
},
mutations: {
	 edit(state,newVal){
	  // newVal是修改后传过来的
	  state.userId=newVal
	 }
},
 类似资料: