当前位置: 首页 > news >正文

Pinia的快捷使用方法

安装Pinia

npm install pinia

在main.js里面引入并注册挂载使用

在src下创建一个store inex.js 

// index.js
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
//更简洁的的模块化 transferringValuesBetweenComponents simulationModule 
//简单定义了两个模块化 也可以在store文件夹下面定义多个js文件
//transferringValuesBetweenComponents 定义了一个模块
export const usePinia = defineStore("transferringValuesBetweenComponents", () => {const count = ref(1);const doubleCount = computed(() => {return count.value * 2})function increase() {count.value++}return { count, doubleCount, increase }
})
//simulationModule模拟模块写法
export const simulationModule = defineStore("simulationModule", () => {const count = ref(0);const doubleCount = computed(() => {return count.value * 3})function increase() {count.value += 3}return { count, doubleCount, increase }
})

在页面中的使用 先引入 再使用

<template><div><h3>count:{{ transferringValuesStore.count }}</h3><h4>doubleCount:{{ transferringValuesStore.doubleCount }}</h4><button @click="transferringValuesStore.increase">调用pinia</button></div>
</template>
<script setup>
import { simulationModule } from "../store/index";
const transferringValuesStore = simulationModule();
</script>

http://www.lryc.cn/news/445188.html

相关文章:

  • 一文搞懂C++继承
  • MFC -文件类控件
  • Hbase操作手册
  • vue组件($refs对象,动态组件,插槽,自定义指令)
  • 构建高可用和高防御力的云服务架构第五部分:PolarDB(5/5)
  • QT窗口无法激活弹出问题排查记录
  • node.js 版本管理
  • 使用Python实现图形学曲线和曲面的NURBS算法
  • SpringBoot3
  • 【Text2SQL】领域优质论文分享
  • 2024全国研究生数学建模竞赛(数学建模研赛)ABCDEF题深度建模+全解全析+完整文章
  • Java项目中异常处理的最佳实践
  • CSS基本概念以及CSS的多种引入方式
  • TiDB 简单集群部署拓扑文件
  • 十三 系统架构设计(考点篇)
  • Java-数据结构-二叉树-习题(三)  ̄へ ̄
  • SpringBoot+Aop+注解方式 实现多数据源动态切换
  • 企业如何高效应对多类型知识产权事务的复杂挑战?
  • openeuler22.03 LTS 源码编译安装nginx1.22.1
  • 图片压缩工具免费怎么找?归纳了这几个压缩工具
  • 【Kubernetes知识点】解读HPA的 thrashing(抖动)问题
  • Unity 设计模式 之 结构型模式 -【装饰者模式】【外观模式】【享元模式】【代理模式】
  • Linux上Qt安装相关的内容及在QtCreator使用QChart模块需要的配置
  • lettuce引起的Redis command timeout异常
  • 【Hadoop】一、Hadoop入门:基础配置、集群配置、常用脚本
  • Ollama:本地运行大模型【含UI界面】
  • 【论文阅读】Grounding Language with Visual Affordances over Unstructured Data
  • 目标检测:滑块验证
  • Unreal Engine 5 C++: 编辑器工具编写入门01(中文解释)
  • 力扣上刷题之C语言实现-Day2