npm install pinia
import { createApp } from 'vue'
import { createPinia } from 'pinia'
const app = createApp(App)
app.use(createPinia())
- 定义一个Store(/src/store/goods/index.js)
import { defineStore } from "pinia";
//
export const goodStore = defineStore('goodStore', {
state:()=>{
return {
goodcount: 100
}
},
//
actions: {
setGoodCount(){
this.goodcount++
}
}
})
- 使用stroe(src/views/goods/index.vue)
<script lang="ts" setup>
import { goodStore } from '@/store/goods/index'
const goodCount = goodStore();
goodCount.setGoodCount();
console.log('goodCount ==== ', goodCount.goodcount);
</script>
网友评论