Modules
为了避免 Model 过于复杂,VueModello 使用 modules 来组成复杂的 Model。每个 module 拥有自己的 state、actions、mutations。当 Model mix 一个 module 时,需要为其指定 module name。
Default module
为了和 mix 的 module 保持一致,VueModello 把直接声明在 Model 上(非 mudule 中)的 state、actions、mutations 归属于名为 “default” 的 module
Example
models/product/model.js
import productList from './product_list'
import newProduct from './new_product'
export default {
moduleName: 'Product'
mixins: {
productList: productList,
newProduct: newProduct
},
// default module state
state () {
return {
constant: { //... }
}
},
// default module actions
actions {
getAllCategories({state, commit, dispatch)) {
//...
}
},
// default module mutations
mutations {
updateProductCategory(state, id, categoryId) {
//....
}
}
}
models/product/product_list.js
export default {
state () {
return {
list: [],
total: 0
}
},
actions: {
queryProductList({state, commit, dispatch}, query) {
//...
}
},
mutations: {
updateProductList(state) {
}
}
}