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