vue3 使用pinia

安装:

 npm install pinia

min.js中引入

import { createApp } from 'vue'
import App from './App.vue'
import { createPinia } from "pinia";
const pinia = createPinia();
const app = createApp(App);
app.use(pinia);
app.mount("#app");

创建仓库 store/user.js

import { defineStore } from "pinia"
export const useUsersStore = defineStore('users', {
    // 其它配置项
    state: () => {
        return {
            name: "张三",
            }
        };
    },
    getters: {

    },
    actions: {

    }
})

使用:

你可能感兴趣的:(javascript,前端,开发语言)