Vue3.0 setup 里使用 vuex
时间:2020-12-10 13:22:08
收藏:0
阅读:1481
import { useStore } from "vuex" import { getCurrentInstance, computed } from "vue" setup(){ const store = useStore() // 获取store 实例 const { ctx } = getCurrentInstance() // 获取当前组件实例 console.log(ctx.$router.currentRoute.value) const count = computed( () => store.state.count) return {count} // 组件中 count 会随着其他的地方的 count 变化而自动相应变化 }
原文:https://www.cnblogs.com/winyh/p/14113434.html
评论(0)