Vuex getter 销毁
Vuex getter destruct
我在 Vuex 中使用 Vue.js,想知道有没有办法像 actions[一样销毁 getters =25=]干什么?
这个getter:
doneTodosCount: (state, getters, rootState, rootGetters) => {
.....
}
变成这样:
doneTodosCount: ({rootGetters}) => {
.....
}
问这个,因为在第一个例子中,我不需要前三个参数 state, getters, rootState 但仍然需要写它们来达到第四个rootGetters
你不能,因为你没有解构任何对象;您需要以正确的顺序列出参数。
我想你可以编写一个忽略前 3 个参数的辅助函数,但老实说,我认为它没有那么有用。
const f = fn => (state, getters, rootState, rootGetters) => fn(rootGetters)
export default {
doneTodosCount: f(rootGetters => {
...
})
}
我在 Vuex 中使用 Vue.js,想知道有没有办法像 actions[一样销毁 getters =25=]干什么?
这个getter:
doneTodosCount: (state, getters, rootState, rootGetters) => {
.....
}
变成这样:
doneTodosCount: ({rootGetters}) => {
.....
}
问这个,因为在第一个例子中,我不需要前三个参数 state, getters, rootState 但仍然需要写它们来达到第四个rootGetters
你不能,因为你没有解构任何对象;您需要以正确的顺序列出参数。
我想你可以编写一个忽略前 3 个参数的辅助函数,但老实说,我认为它没有那么有用。
const f = fn => (state, getters, rootState, rootGetters) => fn(rootGetters)
export default {
doneTodosCount: f(rootGetters => {
...
})
}