这里我只用到了state和mutations
1.vuex文件 store.js
state: {
passwordState:false,//登录状态
},
mutations:{
// 设置修改登录状态的方法
setPasswordState(state,value){
state.passwordState = value;
},
}
2.具体操作页面
import { onMounted } from 'vue'
import { useStore } from 'vuex'
export default {
setup(){
//把useStore赋值
const $store = useStore();
onMounted(()=>{
//拿到vuex的值
console.log($store.state.passwordState) // false
//改变vuex的值
$store.commit('setPasswordState',true) //调用vuex的方法
//再次打印
console.log($store.state.passwordState) // true
})
return{
}
}
}