3👍
✅
setAgeData()
and getAge()
are not actually mutations (they don’t match the signature of a mutation). They should just be utility functions (moved outside the store) that setUsers()
calls, and I don’t see any problem with that.
For example, you could move setAgeData()
and getAge()
into a local function:
// store/index.js
function setAgeData() {/*...*/}
function getAge() {/*...*/}
export default new Vuex.Store({
mutations: {
setUsers(state, users) {
state.users = setAgeData(users)
}
}
})
Or you could move them into a separate file to be imported:
// store/user-utils.js
export function setAgeData() {/*...*/}
export function getAge() {/*...*/}
// store/index.js
import { setAgeData } from './user-utils'
export default new Vuex.Store({
mutations: {
setUsers(state, users) {
state.users = setAgeData(users)
}
}
})
Source:stackexchange.com