Implicit Parametric questions in Vuex documents

clipboard.png

clipboard.png

The value 2 passed in during the

call will not be passed into the state parameter? But directly to the id?

how to implicitly pass in state? The expression of learning C is not quite understood. No, no, no.

Mar.03,2021

store.getters.getTodoById

returns the function you defined

function(id) {}

the parameter id is passed to your function in the call


console.log (store.getters.getTodoById) , you can see why the value passed in is id


what you see is not necessarily the same code as what is actually executed. For example:

config = {
    getVal (state, getters) {
        return (params) => {console.log(state, params)}
        // stateparams
    }
}
function init (config) {
    let state = xx
    let getters = xxx
    config.getVal = config.getVal.call(this, state, getters)
    return config
}

now I've shielded the details of the init function and encapsulated it in a library called vuex.
after init processing, you can use config.getVal (params), directly without passing state.

init(config).getVal('')
Menu