当前位置:网站首页>Pinia(一)初体验快速安装与上手
Pinia(一)初体验快速安装与上手
2022-08-08 08:56:00 【庇耳拉海莱】
Pinia
(/piːnjʌ/
)
安装与快速上手([email protected][email protected]
)
安装
npm install [email protected]
在 main.js
中引入和使用
import {
createPinia } from 'pinia'
const app = createApp(App);
app.use(createPinia());
创建 src/store/index.ts
import {
defineStore } from 'pinia';
export const useCounterStore = defineStore('counter', {
state: () => {
return {
count: 0,
}
},
getters: {
doubleCount: (state) => {
return state.count * 2;
}
},
actions: {
increment(a: number) {
this.count += a
}
}
})
在组件使用
import {
useCounterStore } from '../store/';
import TestPiniaSon from './TestPiniaSon.vue'
const store = useCounterStore();
function countPlus() {
store.increment(1);
}
<div>
<h2>{
{store.count}}</h2>
<button @click="countPlus">countPlus</button>
</div>
边栏推荐
猜你喜欢
随机推荐
安装oracle19c时报错DBT-50000
攻防世界——mfw
Data Governance (3): Data Quality Management
BLOB, TEXT, GEOMETRY or JSON column 'xxxx' can't have a default value
Techwiz OLED:偏振片的发射特性
百度飞浆EISeg高效交互式标注分割软件的使用教程
Raspberry pie 】 【 without WIFI even under the condition of the computer screen
docker部署redis容器问题
【树莓派】在没有显示屏的情况下通过WIFI连电脑
Excel中text函数5中常用方法
【回归预测】基于GPML工具箱的高斯过程回归附matlab代码
炽热如初 向新而生|ISC2022 HackingClub白帽峰会圆满举办
Implementation principle of priority queue
djanjo fourth training
22-08-06 Xi'an EasyExcel implements dictionary table import and export
sed命令
Interviewer: Have you ever used a lock at work?Talk about the advantages, disadvantages and usage scenarios of optimistic locking and pessimistic locking
SSRF漏洞
oracle如何删除表并且释放表空间
AI引领一场新的科学革命