Thinking about vuex of state variables ???

store in access to public variables of the entire project, by setting the mutation to change their

Existing assumed the following code:

const store = new Vuex.Store({
    state: {
        
        userInfo:{
            name:''
        }
    },
    mutations: {
        
        setuserInfo:(state,value) => {
            const obj = state;
            obj.userInfo = value
        }
    },
    getters:{
    
    }
})

UserInfo we define a variable, by mutation method,

1, we turn the page A keepAlive, and the first time mounted the (recorded as vara) the assignment userInfo page for this $ store.state.userInfo (recorded as varb).;

2, then we change the store in the variable B page: this $ store.commit ( 'setuserInfo', res);.

3, when we go back to page A, found userInfo or changed, then the question is, I will be only when mounted to a reference varb copy to vara, after a page change when B makes another point vara res, intuitively, vara or before the point varb, but the result is still vara changed

Possible reasons explain:

In the third step we declare a one assignment:

obj = const State; 
            obj.userInfo = value
of this step should be the fundamental meaning of the state.
userInfo by attributes assigned to the eleven value; that is, to ensure that the initial reference herein interior vue practice should be: 
for (in the let J value) {
obj.userInfo [J] = value [J]
}
guarantees its initial application, and then this.userInfo this. $ store.state, userInfo always point to the same application, so this.userInfo also change with the
not-depth vuex source code, so if this interpretation correct? ?
To be continued. . . . . . . . . . . .

Guess you like

Origin www.cnblogs.com/tony-stark/p/11670873.html