当前位置:网站首页>pinia(菠萝)
pinia(菠萝)
2022-07-23 13:17:00 【逸尘】
1. 什么是pinia
- vuex精简版 ,而且vue官方更加推荐使用。
- 优势又完胜于vuex ,下面我们来了解下pinia。
2.优势
- pinia是整合了vuex5提案的所有功能点,所以说pinia就是Vuex5也不为过
- Vuex3中使用Vuex4,并且还只能作为一个过度的选择存在很大的隐患,所以在 Componsition API 诞生之后,也就设计了全新的状态管理 Pinia
Pinia 和 Vuex
Vuex: State、Gettes、Mutations(同步)、Actions(异步)
Pinia: State、Gettes、Actions(同步异步都支持)
3. 使用
- 安装
npm install pinia - 在main.js中加入
import App from './App.vue'; import router from './router'; import { createApp } from 'vue'; import Antd from 'ant-design-vue'; import 'ant-design-vue/dist/antd.css'; import { createPinia } from 'pinia';//导入pinia const pinia = createPinia();//调用创建pinia createApp(App).use(Antd).use(pinia).use(router).mount('#app') - 去创建pinia仓库(创建/src/store/pinia.js)
import { defineStore } from 'pinia'; export const PiniaStore = defineStore('main', { //导出 pinia仓库 state: () => { //相当于全局的 data() return { name: '逸尘', age: 21 } }, getters: {}, //相当于全局的computed actions: {} //相当于全局methods }) - 使用
<style lang="less" src="./index.less" ></style> <template> <div class="li-head"> <a-button type="primary" style="margin-bottom: 16px" @click="setFold"> <MenuUnfoldOutlined v-if="fold" /> <MenuFoldOutlined v-else /> </a-button> <div>{ { pinia.name }}</div> <div>{ { pinia.age }}</div> </div> </template> <script> import { ref, watch, reactive } from 'vue'; import { PiniaStore } from '../../store/pinia'; const pinia = PiniaStore(); import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons-vue'; export default { name: "head", components: { MenuFoldOutlined, MenuUnfoldOutlined }, props: { fold: Boolean, setFold: Function }, setup(props) { return { pinia } } } </script>
边栏推荐
- 动态规划背包问题之多重背包详解
- Dynamic programming knapsack problem 01 knapsack explanation
- 《STM32MP1 M4裸机CubeIDE开发指南》第六章 STM32Cube固件包
- tensorflow2.X实战系列softmax函数
- 百度编辑器上传图片设置自定义目录
- IIS 部署.NetCore
- leetcode-168.Excel表列名称
- Tan Zhangxi, director of risc-v Foundation: risc-v has gradually expanded from the edge to the center
- 移动端H5 - 手撸一个生命线 timeline
- 网络协议与攻击模拟:wireshark使用、ARP协议
猜你喜欢

僧多粥少?程序员要怎样接私活才能有效提高收入?

Detector: detect objects with recursive feature pyramid and switchable atolos convolution

Cuibaoqiu, vice president of Xiaomi group: open source is the best platform and model for human technological progress

The working principle of PLL. For example, how can our 8MHz crystal oscillator make MCU work at 48mhz or 72mhz

js如果小数是0就减去,不是就保留

Microcomputer principle and technical interface practice in class

Summary of after class homework of Microcomputer Principle and technical interface

LeetCode之等式方程的可满足性

Scale Match for Tiny Person Detection

【C语言】结构体、枚举和联合体
随机推荐
大屏可视化的适配方案
USB基础
Dynamic programming knapsack problem 01 knapsack explanation
使用“soup.h1.text”爬虫提取标题会多一个\
通用分页功能
The first stage of basic knowledge of numpy data analysis (numpy Foundation)
FreeRTOS个人笔记-创建/删除动态任务,启动调度器
层次分析法(MATLAB)
Go interface: go deep into internal principles
(resolved) idea compilation gradle project prompt error no symbol found
How to buy financial products with a return of more than 6%?
leetcode-67.二进制求和
Frequently asked questions about MySQL
Surface family purchase reference
How does MySQL query data that is not in the database?
Priyanka Sharma, general manager of CNCF Foundation: read CNCF operation mechanism
TOPSIS法(MATLAB)
系统内存介绍和内存管理
Go 接口:深入内部原理
移动端H5 - 手撸一个生命线 timeline