最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

pina使用步驟

2023-04-24 10:59 作者:小戶編程  | 我要投稿

安裝pina庫

在命令行中為該項(xiàng)目安裝pinia

npm install pina

vue安裝pinia

在main.js入口文件中導(dǎo)入pinia的創(chuàng)建函數(shù),vue實(shí)例中使用pinia

import?{ createPinia?} from?'pinia'

app.use(createPinia())


?

定義狀態(tài)

創(chuàng)建/src/stores文件夾,創(chuàng)建一個(gè)狀態(tài)管理js,例如計(jì)數(shù)器

/src/stores/counter.js

import?{ defineStore?} from?"pinia";

?

export?const?useCounterStore?= defineStore("counter", {

? state:?() =>?{

? ? return?{ count:?0?};

? },

? // 也可以這樣定義

? // state: () => ({ count: 0 })

? actions:?{

? ? increment() {

? ? ? this.count++;

? ? }

? }

});

使用狀態(tài)

先引入,然后調(diào)用狀態(tài)的屬性和方法。

<template>

? <div>{{ counter.count?}}</div>

</template>

<script?setup>

import?{ useCounterStore?} from?"@/stores/counter";

?

const?counter?= useCounterStore();

counter.count++;

counter.increment();

</script>

<style></style>

?


pina使用步驟的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
高安市| 隆尧县| 开远市| 巫溪县| 丹东市| 新民市| 慈利县| 远安县| 兰州市| 和静县| 望城县| 宣汉县| 双鸭山市| 博白县| 蒙城县| 新泰市| 卢龙县| 绍兴县| 黄平县| 吴川市| 登封市| 锦屏县| 通辽市| 邵阳市| 葫芦岛市| 乐至县| 淮北市| 奇台县| 石楼县| 临邑县| 芷江| 林州市| 西城区| 沈丘县| 西乌| 两当县| 玛纳斯县| 双柏县| 宜宾市| 察隅县| 秦皇岛市|