Vue3里的setup中使用vuex
生活随笔
收集整理的這篇文章主要介紹了
Vue3里的setup中使用vuex
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
useStore
這里我們可以直接從vuex 4.X中解構出useStore方法,就可以在setup中使用vuex的相關函數
template 使用$store
<template><div><h2>{{ $store.state.count }}</h2><button @click="increaseCount">點擊</button></div> </template>//引入路由函數 import { useStore } from "vuex";//使用 setup() {//使用vuexconst store = useStore();//正常使用,相當于store代替了this.$store//store.state. ...console.log(store.state.count);const increaseCount = () => {store.commit("increaseCount");};return { increaseCount }; }?
總結
以上是生活随笔為你收集整理的Vue3里的setup中使用vuex的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue中使用Vue-pdf在线预览
- 下一篇: vue3 echarts5 graph关