拾光记录
218个文档 导航 作者 Gitee
随笔记录4
Hexo博客:基础使用Hexo博客:Next主题Hexo博客:Next进阶使用Hexo博客:Next高级配置
前端知识4
基础知识17
Vue框架19
UniApp14
微信小程序1
Java编程6
Java基础15
SpringBoot31
SpringMVC18
MyBatis9
SpringCloud15
中间件2
数据库4
MySQL13
Redis8
MongoDB10
其他数据库1
Python编程6
Python基础知识Python语法yolo目标检测OpenCV的使用及树莓派平台condauv管理工具
Linux12
Linux常用命令Jar启动脚本VirtualBox安装CentOSVirtualBox安装Ubuntu树莓派安装及使用frp内网穿透ArchLinux:基础系统安装ArchLInux:图形化界面安装ArchLinux:常用软件ArchLinux:深度优化ArchLinux:NiriArchLinux:模块记录
软件工具12
IDEAGitMavenGradleNginx安装Nginx配置JMeter压测OllamaRustFSPicGoVSCodeDocker
创意设计2
Blender:入门知识UI设计基础知识
AI相关9
Claude CodeHermes AgentOpenAI基本使用OpenAI工具调用OpenAI记忆管理OpenAI推理执行OpenAI开发框架Langchainllama.cpp

安装和配置

HBuilderX 4.14版本开始,uni-app已内置了Pinia,无需手动安装,直接在main.js中配置即可

import App from './App'
import { createSSRApp } from 'vue'
// 1. 引入 Pinia
import * as Pinia from 'pinia'

export function createApp() {
    const app = createSSRApp(App)
    // 2. 创建 Pinia 实例并挂载到应用上
    app.use(Pinia.createPinia())
    
    return {
        app,
        Pinia // 3. 切记将 Pinia 返回,这是必须的步骤
    }
}

然后在项目根目录创建sotres/index.js

import {
  defineStore
} from 'pinia'

// 定义 Store
export const useStore = defineStore('storeId', {
  // 存储状态数据
  state: () => ({
    name: '游客',
  }),
})

使用方式

<script setup>
// 使用
import { useStore } from '../../stores/index.js'
const store = useStore()

console.log(store.name)
</script>
安装和配置使用方式