当前位置:网站首页>Pinia (pineapple)
Pinia (pineapple)
2022-07-23 16:55:00 【Dust escape】
1. What is? pinia
- vuex Lite version , and vue It is more recommended to use .
- The advantage is completely superior to vuex , So let's see pinia.
2. advantage
- pinia It is integrated. vuex5 All function points of the proposal , So pinia Namely Vuex5 Too much
- Vuex3 Use in Vuex4, And it can only be used as an excessive choice, which has great hidden dangers , So in Componsition API After birth , It also designs a new state management Pinia
Pinia and Vuex
Vuex: State、Gettes、Mutations( Sync )、Actions( asynchronous )
Pinia: State、Gettes、Actions( Both synchronous and asynchronous support )
3. Use
- install
npm install pinia - stay main.js Add
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';// Import pinia const pinia = createPinia();// Call create pinia createApp(App).use(Antd).use(pinia).use(router).mount('#app') - To create pinia Warehouse ( establish /src/store/pinia.js)
import { defineStore } from 'pinia'; export const PiniaStore = defineStore('main', { // export pinia Warehouse state: () => { // Equivalent to global data() return { name: ' Escape dust ', age: 21 } }, getters: {}, // Equivalent to global computed actions: {} // Equivalent to global methods }) - Use
<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>
边栏推荐
猜你喜欢

国内生产总值(GDP)数据可视化

熵权法优化TOPSIS(MATLAB)

一文带你了解什么是TypeScript

Priyanka Sharma, general manager of CNCF Foundation: read CNCF operation mechanism

TOPSIS法(MATLAB)

YOLOV7

Scale Match for Tiny Person Detection

C#入门系列(二十八) -- LINQ的查询语法

距离IoU损失:包围盒回归更快更好的学习(Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression)

FIO performance testing tool
随机推荐
熵权法优化TOPSIS(MATLAB)
YOLOv4: Optimal Speed and Accuracy of Object Detection
【TensorFlow】检测TensorFlow GPU是否可用
Squeeze-and-Excitation Networks(挤压和激励网络)
C#入门系列(二十八) -- LINQ的查询语法
英特尔nuc能代替主机吗_终于圆满了!最新款的Intel NUC迷你主机上线
Direct exchange
Scale Match for Tiny Person Detection
Heartless sword English Chinese bilingual poem 006. to my wife
pip报错Could not find a version that satisfies the...No matching distribution
Squeeze and incentive networks
Case analysis of building campus information management system with low code
Fastadmin, non super administrator, has been granted batch update permission, but it still shows no permission
YOLOV7
AutoCAD进阶操作
灰色关联分析(MATLAB)
浏览器四大内核
Distance IOU loss: faster and better learning for bounding box regression
Direct exchange
(resolved) idea compilation gradle project prompt error no symbol found