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

Royal O'Brien, executive director of o3df: open source has no boundaries, and all shared sounds will become the actual direction

Solve data functions should return an object (property "visible" must be accessed with "$data.visible")

低代码搭建校园信息化管理系统案例分析

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

《STM32MP1 M4裸机CubeIDE开发指南》第六章 STM32Cube固件包

NodeJs实现token登录注册(KOA2)

Scale Match for Tiny Person Detection

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

微信小程序wx.hideLoading()会关闭toast提示框

Go interface: go deep into internal principles
随机推荐
Microcomputer principle and technical interface practice in class
Visual analysis of real-time epidemic data
UiPath Studio Enterprise 22.4 Crack
leetcode-67.二进制求和
实时疫情数据可视化分析
SSD: Single Shot MultiBox Detector
Introduction to Huawei's new version of datacom certification
Direct exchange
How does MySQL query data that is not in the database?
go run,go build,go install有什么不同
深度学习卷积神经网络论文研读-AlexNet
VMware虚拟机的三种网络模式
Less than 10 days before the PMP Exam on July 30, what should be done?
Advanced authentication of uni app [Day12]
Cuibaoqiu, vice president of Xiaomi group: open source is the best platform and model for human technological progress
Network protocol and attack simulation: Wireshark use, ARP Protocol
Summary of after class homework of Microcomputer Principle and technical interface
YOLOv4: Optimal Speed and Accuracy of Object Detection
How to buy financial products with a return of more than 6%?
Tan Zhangxi, director of risc-v Foundation: risc-v has gradually expanded from the edge to the center