store.js
const state = {
userPermission: [],
}
const getters = {
getUserPermission: state => state.userPermission,
}
const mutations = {
userPermission(state,userPermission){
localStorage.userPermission = JSON.stringify(userPermission)
state.userPermission = localStorage.userPermission
}
}
const actions = {
userPermission({commit},userPermission){
return new Promise(function(resolve,reject){
commit("userPermission",userPermission)
})
}
}
export default {
state,
getters,
mutations,
actions
import {mapState} from "vuex"
computed: mapState ({ in
}
component
userPermission(state){
alert(1)//
let userPermission = JSON.parse(localStorage.getItem("getUserPermission"))
if(state.userPermission.length === 0){
return
}
return state.userPermission
}
})
use it for the first time, please advise