Web前端之路1024Vue.js

2、使用Pinia

2023-08-30  本文已影响0人  圆梦人生
npm install pinia
import { createApp } from 'vue'
import { createPinia } from 'pinia'

const app = createApp(App)
app.use(createPinia())
import { defineStore } from "pinia";
//
export const goodStore = defineStore('goodStore', {
   state:()=>{
    return {
        goodcount: 100 
    }
   },
   //
   actions: {
    setGoodCount(){
        this.goodcount++
    }
   }
})
<script lang="ts" setup>
import { goodStore } from '@/store/goods/index'
const goodCount = goodStore();
goodCount.setGoodCount();
console.log('goodCount ==== ', goodCount.goodcount);

</script>
上一篇 下一篇

猜你喜欢

热点阅读