首页 > 其他 > 详细

Vue3.0 setup 里使用 vuex

时间:2020-12-10 13:22:08      阅读:1478      评论:0      收藏:0      [点我收藏+]
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 变化而自动相应变化
}

  

Vue3.0 setup 里使用 vuex

原文:https://www.cnblogs.com/winyh/p/14113434.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!