ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

学习Pinia

2026/8/16 12:12:47 拓冰建站 浏览量
学习Pinia

Pinia

  • 1.介绍Pinia
  • 2.起步 安装

1.介绍Pinia

Pinia.js 有如下特点:

完整的 ts 的支持;
足够轻量,压缩后的体积只有1kb左右;
去除 mutations,只有 state,getters,actions;
actions 支持同步和异步;
代码扁平化没有模块嵌套,只有 store 的概念,store 之间可以自由使用,每一个store都是独立的
无需手动添加 store,store 一旦创建便会自动添加;
支持Vue3 和 Vue2
pinia的链接: pinia

2.起步 安装

yarn add pinianpm install pinia
  • 引入注册Vue3
import { createApp } from 'vue'
import App from './App.vue'
import {createPinia} from 'pinia'const store = createPinia()
let app = createApp(App)app.use(store)app.mount('#app')
  • Vue2 使用
import { createPinia, PiniaVuePlugin } from 'pinia'Vue.use(PiniaVuePlugin)
const pinia = createPinia()new Vue({el: '#app',// other options...// ...// note the same `pinia` instance can be used across multiple Vue apps on// the same pagepinia,
})

待完善。。。。。