* pinia是什么?
* Pinia官网:Pinia 是 Vue 的存储库,它允许您跨组件/页面共享状态。
* 即数据共享。在使用过pinia后,相信你也会对它爱不释手的,下面我们来聊聊如何安装。
目录
安装pinia
- 来到你的项目文件夹
- 在vscode的终端中执行:npm i pinia -D
- 在 /src/modules文件夹下新建文件 pinia.js
- 写入:
import { createPinia } from "pinia"
const pinia = createPinia()
export default pinia
修改main.js
- 增加:
import pinia from "./modules/pinia"
//...
app.use(pinia)
- 最终main.js文件:
创建stores
- 在 /src文件夹内新建文件夹stores,用来存放状态管理
- 这里我们示例创建一个计数管理,counter.js
- 里面写入:
import { defineStore } from "pinia"
export const useCounterStore = defineStore('counter', {
state() {
return {
num:1
}
},
actions: {
inc() {
++(this.num);
}
}
})
使用counter
- 在你想使用counter的页面中导入并使用,这里以home.vue示例:
<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>
- home页面效果:
- 进入页面后,计数为1
- 点击按钮时,每点击一次,计数 + 1
deep web drug links onion market
deep web sites bitcoin dark web
deep web markets deep web links
tor markets darknet links
darknet drug links onion market
dark web market links darkweb marketplace
darknet websites bitcoin dark web
dark web market list dark market link
dark markets tor dark web
how to access dark web darknet market
dark internet dark net
dark web access tor markets
tor market url tor markets 2023
dark market onion darknet marketplace
deep web markets darkmarket
darkmarket list dark markets
tor darknet dark web access
onion market tor market
darkmarket url dark markets
darknet market list tor markets links
dark markets the dark internet
deep web markets tor market url
darkweb marketplace dark websites
dark market 2023 darknet links
dark web search engine deep web markets
dark web sites links tor markets links
dark web drug marketplace dark web market
darknet market dark web links
deep web drug links tor market url
darknet market links blackweb official website
dark website darknet search engine
deep web drug url dark market link
dark web market dark web drug marketplace
black internet dark web search engine
darknet drug store dark website
free dark web dark markets
darknet links darknet drug store
dark web link darkmarket url
deep web drug links dark web drug marketplace
drug markets dark web dark web link
dark web sites links dark web access
deep web drug url tor darknet
darkweb marketplace dark website
darknet drug links darknet markets 2023
tor marketplace dark web sites links
dark web market darknet seiten
dark web sites dark web sites
dark markets 2023 drug markets onion
tor market links tor marketplace
dark web search engines dark market 2023