pinia基础使用

复制代码
import {defineStore} from 'pinia'
import {StoreName} from './store-name'
// StoreName是id,用于区分不同的store,自定义即可
export const useStore = defineStore(StoreName.Test, {
  state: () => ({
    count: 0,
    sex: '顶顶顶'
  }),
  getters: {

  },
  actions: {
    increment() {
      this.count++
    },
  },
})
复制代码
复制代码
<template>
<div>
  直接通过实例.就可以获取
  {{ store.count }}---- {{ store.sex }}
</div>
</template>

<script setup lang='ts'>
import { useStore } from '../store'
// defineStore返回的是个hook,需要实例化
const store = useStore()
</script>

<style scoped lang='scss'>

</style>
复制代码

 

posted on   ChoZ  阅读(3)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
历史上的今天:
2023-02-22 Vue3中使用JSX简明语法
2023-02-22 TS补充笔记

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示