当前位置:网站首页>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>
边栏推荐
猜你喜欢

General paging function

阿里平头哥CPU技术生态负责人陈炜:平头哥的发展之路

Une solution complète au problème du sac à dos dans la programmation dynamique

SurFace家族选购参照

COPU副主席刘澎:中国开源在局部领域已接近或达到世界先进水平

Circuit structure and output mode of GPIO port of 32-bit single chip microcomputer

移动端H5 - 手撸一个生命线 timeline

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

华为新版Datacom认证介绍

tensorflow2.X实战系列softmax函数
随机推荐
pytest接口自动化测试框架 | pytest生成简单测试报告
USB基础
系统内存介绍和内存管理
Heartless sword English Chinese bilingual poem 006. to my wife
[note] linear regression
一道反序列化的CTF题分享
国内生产总值(GDP)数据可视化
SQL156 各个视频的平均完播率
动态规划背包问题之完全背包详解
IIS 部署.NetCore
Squeeze and incentive networks
微机原理与技术接口课后作业总结
Direct exchange
Go 接口:深入内部原理
TS encapsulates the localstorage class to store information
移动、电信、联通:5G To B的花式解法
灰色关联分析(MATLAB)
UiPath Studio Enterprise 22.4 Crack
怎么购买收益在6%以上的理财产品?
深度学习卷积神经网络论文研读-AlexNet