当前位置:网站首页>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>
边栏推荐
- Offensive and defensive world - web2
- Want to use SQL to achieve two days after the data contrast, the new data sheet and a list of tags
- 数学基础(一)矩阵对角化、SVD分解以及应用
- BLOB, TEXT, GEOMETRY or JSON column 'xxxx' can't have a default value
- 实体List转为excel
- 力扣142-环形链表——链表&快慢指针法&哈希表法
- Redis读写分离(三)
- X射线聚焦系统
- 各位大佬想问下, flinkcdc采集oracle我看了下延迟大概两分钟左右,想问下有啥解决方法吗
- Stanford Fall 21: Practical Machine Learning [Chapter 5]
猜你喜欢
Literature Learning (part33)--Clustering by fast search and find of density peaks
DVWA full level detailed customs clearance tutorial
SSRF漏洞
数据库调优:Mysql索引对group by 排序的影响
手机APP测试流程规范和方法你知道多少?
六十分之七——焦虑路上的涅槃
要写脚本,编程不好不要紧--浅谈CTF中脚本的编写方法
巧用Prometheus来扩展kubernetes调度器
67:第五章:开发admin管理服务:20:开发【解冻/冻结用户,接口】;(用户状态变更后,需要刷新用户状态,即变更用户会话信息:我们一般通过“删除redis中会话信息,强制用户重新登录“来做的;)
regular expression
随机推荐
hdu4635 Strongly connected(tarjan计算强连通通分量+缩点+思想)
攻防世界——lottery
22-08-06 Xi'an EasyExcel implements dictionary table import and export
Redis读写分离(三)
各位大佬想问下, flinkcdc采集oracle我看了下延迟大概两分钟左右,想问下有啥解决方法吗
Offensive and defensive world - web2
蔚来杯2022牛客暑期多校训练营6 ABGJM
2022 - image classification 】 【 MaxViT ECCV
简单理解MVVM模型
【Enumeration】Continuous factor
[Optimized scheduling] Based on particle swarm to realize economic scheduling optimization of microgrid under grid-connected model with matlab code
Golang实现sha256或sha512加密
Kotlin协程:生命周期原理
sed命令
MySQL中的锁机制详解
DVWA全级别详细通关教程
Literature Learning (part33)--Clustering by fast search and find of density peaks
在数学里,minimum 和 minimal 有啥区别吗?
Excel中text函数5中常用方法
Go 函数与方法