Vue3.0 setup 里使用 vuex


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 变化而自动相应变化
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM