[vue/vite/pinia]在vscode中给vite项目安装pinia状态管理

/ 25,529评论 / 52293阅读 / 4点赞

* pinia是什么?

* Pinia官网:Pinia 是 Vue 的存储库,它允许您跨组件/页面共享状态

* 即数据共享。在使用过pinia后,相信你也会对它爱不释手的,下面我们来聊聊如何安装。

安装pinia

import { createPinia } from  "pinia"

const pinia = createPinia()

export default pinia

修改main.js

import pinia from "./modules/pinia"
//...
app.use(pinia)

创建stores

import { defineStore } from "pinia"

export const useCounterStore = defineStore('counter', {
    state() {
        return {
            num:1
        }
    },
    actions: {
        inc() {
            ++(this.num);
        }
    }
})

使用counter

<script setup>
import { useCounterStore } from "../stores/counter"

const counter = useCounterStore()
</script>

<template>
    <div>这里是home.vue捏</div>
    <span>{{counter.num}}</span>
    <button @click="counter.inc()">点我</button>
</template>
  1. Charliebut说道:

    deep web markets dark web drug marketplace dark web market list

  2. Roberthoice说道:

    darkmarket list dark web sites tor markets links

  3. HenryTor说道:

    darkmarkets darknet links deep web drug url

  4. RonaldLaf说道:

    darknet drug store dark market darkmarket 2023

  5. Scottbof说道:

    tor marketplace darkweb marketplace darknet links

  6. IgnacioMob说道:

    deep web drug links darkweb marketplace dark web search engines

  7. WilliamPhync说道:

    dark web drug marketplace tor marketplace blackweb

  8. Eugenewoome说道:

    deep web drug store dark market link darknet search engine

  9. Roberttainy说道:

    blackweb official website dark web markets blackweb

  10. Davidnealk说道:

    darknet market how to get on dark web tor markets 2023

  11. EdwardTow说道:

    dark market url darknet drug links darknet marketplace

  12. WesleyInags说道:

    darknet marketplace darknet site deep web drug url

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注