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