1 回答
TA贡献1853条经验 获得超6个赞
使用 Vuex getter 并在计算的 getter 中引用它们,以及在计算的 setter 中检索新值并使用它在存储中提交突变是一个不错的选择。所以你的商店会变成:
const store = new Vuex.Store({
state: {
drawerState: false
},
mutations: {
toggleDrawerState (state, data) {
state.drawerState = data
}
},
getters : {
drawerState: (state) => state.drawerState
}
})
您的导航抽屉组件将变为:
<template>
<v-navigation-drawer v-model="drawerState" app clipped color="grey lighten-4">
<!-- content -->
</v-navigation-drawer>
</template>
<script>
export default {
name: 'NavigationDrawer',
computed: {
drawerState: {
get () { return this.$store.getters.drawerState },
set (v) { return this.$store.commit('toggleDrawerState', v) }
}
}
}
</script>
这是一个显示完整示例的代码笔: https ://codepen.io/JamieCurnow/pen/wvaZeRe
添加回答
举报