一般写法
123456
const state = { a: 1, b: { c: 1}};export default { state };
如果有重置状态的需求
1234567891011121314151617181920212223
const defaultState = () => ({ a: 1, b: { c: 1}});const state = defaultState();const actions = { reset({commit}) { commit('reset'); }};const mutations = { reset(state) { const initState = defaultState(); Object.keys(state).forEach( x => { state[x] = initState[x]; }); }};export default { state, actions, mutations };
URARA
乌拉拉大陆
tokyo
Posts
115
Categories
11
Tags
38
linux
javascript / linux
javascript
Update your browser to view this website correctly. Update my browser now
×