国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vue——狀態(tài)管理庫(kù)Pinia

這篇具有很好參考價(jià)值的文章主要介紹了Vue——狀態(tài)管理庫(kù)Pinia。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

寫(xiě)在前面:本文參考小滿(mǎn)大牛的pinia專(zhuān)欄

一、Vuex與Pinia

Vuex 和 Pinia 均是 Vue.js 的狀態(tài)管理庫(kù),它們?yōu)?Vue 應(yīng)用程序提供了一種集中式的、可預(yù)測(cè)的狀態(tài)管理解決方案。

Vuex 是 Vue.js 官方推薦的狀態(tài)管理庫(kù)之一。它的核心概念包括 state、mutation、action 和 getter。其中,state 代表應(yīng)用程序的狀態(tài)數(shù)據(jù),在 Vuex 中存儲(chǔ)為唯一的來(lái)源,mutation 用于修改狀態(tài)數(shù)據(jù)并確保數(shù)據(jù)變化的可追蹤性,action 用于處理異步操作或組合多個(gè) mutation 操作,getter 可以讓我們對(duì) state 進(jìn)行計(jì)算和派生,并使其變得更加易于訪(fǎng)問(wèn)。一個(gè) Vuex store 實(shí)例是一個(gè)全局 JavaScript 對(duì)象,可以在所有組件中通過(guò)注入來(lái)進(jìn)行訪(fǎng)問(wèn)和操作。

Pinia 是一個(gè)新的狀態(tài)管理庫(kù),也是專(zhuān)門(mén)為 Vue 3 開(kāi)發(fā)的。它提供了一個(gè)類(lèi)似于 Vuex 的狀態(tài)管理模式,但采用最新的 Vue 3 API 構(gòu)建。相比 Vuex,Pinia 更簡(jiǎn)單、更輕量,更加靈活,并支持 TypeScript 類(lèi)型檢查。

與 Vuex 相比,Pinia 沒(méi)有嚴(yán)格的命名約定,可以自由拆分邏輯、支持獨(dú)立實(shí)例、執(zhí)行更輕量級(jí)的代碼等。但不同于 Vuex,它并沒(méi)有內(nèi)置支持模塊化和嚴(yán)格調(diào)試工具。

以下是Pinia的特點(diǎn)

  • 完整的 ts 的支持;
  • 足夠輕量,壓縮后的體積只有1kb左右;
  • 去除 mutations,只有 state,getters,actions;
  • actions 支持同步和異步;
  • 代碼扁平化沒(méi)有模塊嵌套,只有 store 的概念,store 之間可以自由使用,每一個(gè)store都是獨(dú)立的
  • 無(wú)需手動(dòng)添加 store,store 一旦創(chuàng)建便會(huì)自動(dòng)添加;
  • 支持Vue3 和 Vue2

Pinia官方文檔

二、安裝、引入Pinia

安裝:npm install piniayarn add pinia
引入注冊(cè):
Vue3的引入方法
main.ts

import { createApp } from 'vue'
import App from './App.vue'
// Vue3的引入方法
import {createPinia} from 'pinia'

const store = createPinia()

let app = createApp(App)
 
app.use(store)

app.mount('#app')

Vue2的引入方法
main.ts

import { createPinia, PiniaVuePlugin } from 'pinia'
 
Vue.use(PiniaVuePlugin)
const pinia = createPinia()
 
new Vue({
  el: '#app',
  pinia,
})

三、初始化創(chuàng)建Store

新建文件夾
Vue——狀態(tài)管理庫(kù)Pinia
index.ts用于管理倉(cāng)庫(kù),store-name.ts用于存儲(chǔ)所有枚舉的倉(cāng)庫(kù)名。
store-name.ts

// 枚舉所有倉(cāng)庫(kù)名并暴露
export const enum Names {
    TEST = 'TEST'
}

index.ts

// 導(dǎo)入定義倉(cāng)庫(kù)的方法
import { defineStore } from "pinia";
// 導(dǎo)入枚舉的所有倉(cāng)庫(kù)名
import { Names } from "./store-name";

// defineStore()定義一個(gè)倉(cāng)庫(kù),第一個(gè)參數(shù)作為名稱(chēng),也可看作是id
// 這個(gè)id(名稱(chēng))是必要的,Pinia使用它來(lái)講store連接DevTools,可以通過(guò)調(diào)試工具查看
export const useTestStore = defineStore(Names.TEST, {
    state: () => {
        return {
            // 定義初始化的值
            current: 1,
            name: '小5'
        }
    },
    // 類(lèi)似于computed可以幫我們修飾我們的值
    getters: {

    },
    // 可以操作異步 和 同步 提交state
    actions: {

    }
})

簡(jiǎn)單的使用倉(cāng)庫(kù)的數(shù)據(jù)
App.vue

<template>
  <div>pinia-current:{{ Test.current }}</div>
  <div>pinia-name:{{ Test.name }}</div>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();
</script>

<style lang="scss" scoped></style>

結(jié)果展示:
Vue——狀態(tài)管理庫(kù)Pinia

四、修改State值的五種方式

1.直接修改

State是允許不在倉(cāng)庫(kù)中直接修改值的,這與Vuex不同,Vuex要通過(guò)commitdispatch方法調(diào)用倉(cāng)庫(kù)修改。

<template>
  <div>pinia-current:{{ Test.current }}</div>
  <div>pinia-name:{{ Test.name }}</div>
  <div style="display: flex; flex-direction: column">
    <button @click="change">change</button>
  </div>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();

const change = () => {
  Test.current++;
};
</script>

<style lang="scss" scoped></style>

2.批量修改

在倉(cāng)庫(kù)的實(shí)例上有$patch方法可以批量修改多個(gè)值

<template>
  <div>pinia-current:{{ Test.current }}</div>
  <div>pinia-name:{{ Test.name }}</div>
  <div style="display: flex; flex-direction: column">
    <button @click="bulkChange">批量change</button>
  </div>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();

const bulkChange = () => {
  Test.$patch({
    current: 888,
    name: "小4",
  });
};
</script>

<style lang="scss" scoped></style>

3.批量修改工廠函數(shù)形式

推薦使用函數(shù)形式 可以自定義修改邏輯

<template>
  <div>pinia-current:{{ Test.current }}</div>
  <div>pinia-name:{{ Test.name }}</div>
  <div style="display: flex; flex-direction: column">
    <button @click="funChange">工廠函數(shù)實(shí)現(xiàn)批量change</button>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();

const funChange = () => {
  Test.$patch((state) => {
    (state.current = 999), (state.name = "小3");
  });
};
</script>

<style lang="scss" scoped></style>

4.通過(guò)原始對(duì)象修改整個(gè)實(shí)例

$state您可以通過(guò)將store的屬性設(shè)置為新對(duì)象來(lái)替換store的整個(gè)狀態(tài)

缺點(diǎn)就是必須修改整個(gè)對(duì)象的所有屬性,可以用結(jié)構(gòu)賦值的方式解決這個(gè)缺點(diǎn)。

<template>
  <div>pinia-current:{{ Test.current }}</div>
  <div>pinia-name:{{ Test.name }}</div>
  <div style="display: flex; flex-direction: column">
    <button @click="allChange">必須修改全部的寫(xiě)法(不推薦寫(xiě)法)</button>
  </div>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();

const allChange = () => {
  Test.$state = {
    ...Test.$state,
    name: "小2",
  };
};
</script>

<style lang="scss" scoped></style>

5.通過(guò)actions修改

在倉(cāng)庫(kù)中定義Actions
在倉(cāng)庫(kù)的actions 中直接使用this就可以指到state里面的值
store/index.ts

import { defineStore } from "pinia";
import { Names } from "./store-name";

export const useTestStore = defineStore(Names.TEST, {
    state: () => {
        return {
            current: 1,
            name: '小5'
        }
    },
    getters: {

    },
    // 可以操作異步 和 同步 提交state
    actions: {
        // 不能寫(xiě)箭頭函數(shù) 否則this會(huì)指向錯(cuò)誤
        setCurrent(num:number) {
            this.current = num
        }
    }
})

直接在App.vue實(shí)例中調(diào)用

<template>
  <div>pinia-current:{{ Test.current }}</div>
  <div>pinia-name:{{ Test.name }}</div>
  <div style="display: flex; flex-direction: column">
    <button @click="actionsChange">使用actions修改</button>
  </div>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();

const actionsChange = () => {
  Test.setCurrent(555);
};
</script>

<style lang="scss" scoped></style>

6.結(jié)果展示

App.vue

<template>
  <div>pinia-current:{{ Test.current }}</div>
  <div>pinia-name:{{ Test.name }}</div>
  <div style="display: flex; flex-direction: column">
    <button @click="change">change</button>
    <button @click="bulkChange">批量change</button>
    <button @click="funChange">工廠函數(shù)實(shí)現(xiàn)批量change</button>
    <button @click="allChange">必須修改全部的寫(xiě)法(不推薦寫(xiě)法)</button>
    <button @click="actionsChange">使用actions修改</button>
  </div>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();

const change = () => {
  Test.current++;
};
const bulkChange = () => {
  Test.$patch({
    current: 888,
    name: "小4",
  });
};
const funChange = () => {
  Test.$patch((state) => {
    (state.current = 999), (state.name = "小3");
  });
};
const allChange = () => {
  Test.$state = {
    ...Test.$state,
    name: "小2",
  };
};
const actionsChange = () => {
  Test.setCurrent(555);
};
</script>

<style lang="scss" scoped></style>

結(jié)果展示:
Vue——狀態(tài)管理庫(kù)Pinia

五、解構(gòu)store

在Pinia是不允許直接解構(gòu)state的數(shù)據(jù)的,數(shù)據(jù)會(huì)失去響應(yīng)式。

const Test = useTestStore()
// 直接解構(gòu)失去響應(yīng)式
const { current, name } = Test

差異對(duì)比:

<template>
  <div>響應(yīng)式的值:{{ Test.current }}</div>
  <div>解構(gòu)出的非響應(yīng)式值:{{ current }}--{{ name }}</div>
  <button @click="change">change</button>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();
const { current, name } = Test;
const change = () => {
  Test.current++;
};
</script>

<style lang="scss" scoped></style>

結(jié)果展示:
Vue——狀態(tài)管理庫(kù)Pinia
解決方案:
使用pinia的storeToRefs()方式將數(shù)據(jù)響應(yīng)式化。如下:

// 引入
import { storeToRefs } from "pinia";
import { useTestStore } from "./store";

const Test = useTestStore();
// 響應(yīng)式化
const { current, name } = storeToRefs(Test);
const change = () => {
  Test.current++;
};

結(jié)果展示:
Vue——狀態(tài)管理庫(kù)Pinia

六、actions和getters

store/index.ts

import { defineStore } from "pinia";
import { Names } from "./store-name";

type User = {
    name: string,
    age: number
}

let result:User = {
    name: '小5',
    age: 18
}

const Login = (): Promise<User> => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                name: "小4",
                age: 17
            })
        })
    })
}

export const useTestStore = defineStore(Names.TEST, {
    state: () => {
        return {
            // 類(lèi)型斷言
            // <type>{} 通常用于類(lèi)型斷言,表示將某個(gè)值強(qiáng)制轉(zhuǎn)換成指定的類(lèi)型。
            user: <User>{},
            name: 'xiao5'
        }
    },
    // 類(lèi)似于computed可以幫我們修飾我們的值
    getters: {
        newName(): string {
            return `$-${this.name}`
        }
    },
    // 可以操作異步 和 同步
    actions: {
        // 不能寫(xiě)箭頭函數(shù) 否則this會(huì)指向錯(cuò)誤
        // 同步
        setUser1() {
            this.user = result
            this.name = '小8'
        },
        // 異步
        async setUser2() {
            const result = await Login()
            this.user = result
            this.name = '小7'
        },
    }
})

App.vue

<template>
  <div>actions:{{ Test.user }}</div>
  <button @click="change1">同步</button>
  <button @click="change2">異步</button>
  <div>getters:{{ Test.newName }}</div>
</template>

<script setup lang="ts">
import { useTestStore } from "./store";

const Test = useTestStore();
const change1 = () => {
  Test.setUser1();
};
const change2 = () => {
  Test.setUser2();
};
</script>

<style lang="scss" scoped></style>

結(jié)果展示:
Vue——狀態(tài)管理庫(kù)Pinia
另外,多個(gè)actions可以相互調(diào)用,多個(gè)getters也可以相互調(diào)用。

七、API

1.$reset

重置store到它的初識(shí)狀態(tài)

import { useTestStore } from "./store";
const Test = useTestStore();
const reset = () => {
  Test.$reset();
};

2.$subscribe

用于訂閱state的改變,只要有state的變化就會(huì)觸發(fā)這個(gè)函數(shù)
$subscribe的第一個(gè)參數(shù)是個(gè)回調(diào)函數(shù)

Test.$subscribe((args, state) => {
  console.log("======>", args);
  console.log("======>", state);
});

返回值args主要包括effect、target、storeId等信息,state是state數(shù)據(jù)變化后的狀態(tài)。如下圖
Vue——狀態(tài)管理庫(kù)Pinia
第二個(gè)參數(shù)是是一個(gè)配置對(duì)象

Test.$subscribe(
  (args, state) => {
    console.log("======>", args);
    console.log("======>", state);
  },
  {
    detached: true,
    deep: true,
    flush: "post",
  }
);

這三種配置詳細(xì)如下:
detached(脫離狀態(tài)):指組件從其父級(jí)組件或 DOM 樹(shù)中被移除的狀態(tài)。在這種狀態(tài)下,組件不再接收更新,并且可以被銷(xiāo)毀。Vue 2.x 中通過(guò)調(diào)用 $destroy() 方法來(lái)銷(xiāo)毀組件,Vue 3.x 中則使用 teleport、keepAlive 等組合來(lái)控制組件的生命周期。

deep(深度監(jiān)聽(tīng)):指對(duì)一個(gè)對(duì)象進(jìn)行深度監(jiān)聽(tīng),在該對(duì)象的所有屬性的值發(fā)生改變時(shí),都能夠得到通知。在 Vue.js 中,可以使用 vm.$watch() 方法來(lái)實(shí)現(xiàn)對(duì)數(shù)據(jù)的深度監(jiān)聽(tīng),Vue 3.x 中也提供了相應(yīng)的 API 實(shí)現(xiàn)深度監(jiān)聽(tīng)。

flush(刷新策略):指一種更新數(shù)據(jù)后如何刷新頁(yè)面的策略。在 Vue.js 中,默認(rèn)的刷新策略是異步批處理模式(nextTick 模式),即將所有數(shù)據(jù)的更新操作放入一個(gè)隊(duì)列中,在下一個(gè) tick 執(zhí)行更新操作,以減少不必要的 DOM 操作和提高性能。除此之外,Vue.js 還支持同步刷新(sync)、立即刷新(pre)等刷新策略。

3.$onAction

用于訂閱actions的調(diào)用,只要有actions被調(diào)用就會(huì)觸發(fā)這個(gè)函數(shù)。

Test.$onAction((args) => {
  console.log(args);
});

返回值args主要包括after回調(diào),args(actions傳遞的參數(shù)),name(觸發(fā)的actions名字),onError(錯(cuò)誤回調(diào)),store(store實(shí)例)等。如下圖
Vue——狀態(tài)管理庫(kù)Pinia

八、pinia插件

pinia 和 vuex 都有一個(gè)通病 頁(yè)面刷新?tīng)顟B(tài)會(huì)丟失

我們可以寫(xiě)一個(gè)pinia 插件緩存他的值
參考博客:滿(mǎn)哥牛文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-466063.html

到了這里,關(guān)于Vue——狀態(tài)管理庫(kù)Pinia的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue3學(xué)習(xí)-Pinia狀態(tài)管理

    定義一個(gè)Store 這個(gè) name ,也稱(chēng)為 id ,是必要的,Pinia 使用它來(lái)將 store 連接到 devtools。 將返回的函數(shù)命名為 use… 是跨可組合項(xiàng)的約定,以使其符合你的使用習(xí)慣。 使用 store 一旦 store 被實(shí)例化,你就可以直接在 store 上訪(fǎng)問(wèn) state 、 getters 和 actions 中定義的任何屬性 store 是一

    2024年02月14日
    瀏覽(15)
  • Vue | Vue.js 全家桶 Pinia狀態(tài)管理

    Vue | Vue.js 全家桶 Pinia狀態(tài)管理

    ??? Vue?.js專(zhuān)欄:Node.js Vue.js 全家桶 Pinia狀態(tài)管理 ????? 個(gè)人簡(jiǎn)介:一個(gè)不甘平庸的平凡人?? ? 個(gè)人主頁(yè):CoderHing的個(gè)人主頁(yè) ?? 格言: ?? 路漫漫其修遠(yuǎn)兮,吾將上下而求索?? ?? 你的一鍵三連是我更新的最大動(dòng)力?? 目錄 一、Pinia和Vuex的對(duì)比 什么是Pinia呢? Pina和

    2024年01月16日
    瀏覽(119)
  • Vue最新?tīng)顟B(tài)管理工具Pinia——徹底搞懂Pinia是什么

    Vue最新?tīng)顟B(tài)管理工具Pinia——徹底搞懂Pinia是什么

    知識(shí)專(zhuān)欄 專(zhuān)欄鏈接 Vuex知識(shí)專(zhuān)欄 https://blog.csdn.net/xsl_hr/category_12158336.html?spm=1001.2014.3001.5482 Vuex官方文檔 https://vuex.vuejs.org/zh/ Pinia官方文檔 https://pinia.web3doc.top/ 最近在 前端的深入學(xué)習(xí)過(guò)程 中,接觸了與 狀態(tài)管理 相關(guān)的內(nèi)容,涉及到 與vue2適配的vuex 和 與vue3適配的pinia ,因此

    2024年02月03日
    瀏覽(52)
  • vue3 快速入門(mén)系列 —— 狀態(tài)管理 pinia

    vue3 快速入門(mén)系列 —— 狀態(tài)管理 pinia

    其他章節(jié)請(qǐng)看: vue3 快速入門(mén) 系列 vue3 狀態(tài)管理這里選擇 pinia。 雖然 vuex4 已支持 Vue 3 的 Composition API,但是 vue3 官網(wǎng)推薦新的應(yīng)用使用 pinia —— vue3 pinia redux、mobx、vuex、pinia都是集中式狀態(tài)管理工具。與之對(duì)應(yīng)的就是分布式。 Pinia 符合直覺(jué) 的 Vue.js 狀態(tài)管理庫(kù) 甚至讓你忘

    2024年04月26日
    瀏覽(16)
  • vue:狀態(tài)管理庫(kù)及其部分原理(Vuex、Pinia)

    多組件的狀態(tài)共享問(wèn)題: 當(dāng)多個(gè)組件需要訪(fǎng)問(wèn)和修改相同的數(shù)據(jù)時(shí),我們需要在組件之間傳遞 props或者使用事件總線(xiàn)。當(dāng),應(yīng)用就會(huì)變得難以維護(hù)和調(diào)試。 多組件狀態(tài)同步問(wèn)題: 當(dāng)一個(gè)組件修改了狀態(tài),其他組件可能無(wú)法立即得知該變化。 狀態(tài)變更的追蹤問(wèn)題: 無(wú)法追蹤

    2024年01月19日
    瀏覽(28)
  • 深入 Pinia:從代碼出發(fā)探索 Vue 狀態(tài)管理的奧秘

    深入 Pinia:從代碼出發(fā)探索 Vue 狀態(tài)管理的奧秘

    ?? 項(xiàng)目地址:https://github.com/mk965/read-pinia ??????? 本節(jié)代碼:https://github.com/mk965/read-pinia/tree/article_1 ??源碼地址: github.com/vuejs/pinia ??打包文件: rollup.config.js ??入口文件: packages/pinia/src/index.ts 將 pinia/packages/pinia/src 目錄下的所有文件復(fù)制到我們之前生成項(xiàng)目的 /src

    2023年04月25日
    瀏覽(20)
  • vue 全局狀態(tài)管理(簡(jiǎn)單的store模式、使用Pinia)

    vue 全局狀態(tài)管理(簡(jiǎn)單的store模式、使用Pinia)

    多個(gè)組件可能會(huì)依賴(lài)同一個(gè)狀態(tài)時(shí),我們有必要抽取出組件內(nèi)的共同狀態(tài)集中統(tǒng)一管理,存放在一個(gè)全局單例中,這樣任何位置上的組件都可以訪(fǎng)問(wèn)其中的狀態(tài)或觸發(fā)動(dòng)作 通過(guò)自定義一個(gè)store模式實(shí)現(xiàn)全局的狀態(tài)管理,實(shí)例如下 有兩個(gè)組件a、b共享store和store2兩個(gè)狀態(tài),我們

    2024年02月13日
    瀏覽(21)
  • vue 3 第三十一章:狀態(tài)管理(Pinia基礎(chǔ)知識(shí))

    狀態(tài)管理是現(xiàn)代 Web 應(yīng)用開(kāi)發(fā)中的一個(gè)重要概念。Vue 3 中的狀態(tài)管理庫(kù) Pinia ,是一個(gè)基于 Vue 3 Composition API 的狀態(tài)管理庫(kù),它提供了一種 簡(jiǎn)單 、 靈活 的方式來(lái)管理應(yīng)用程序的狀態(tài),同時(shí)還具有 高性能 和 可擴(kuò)展性 。 Pinia 在某種程度上來(lái)說(shuō),也可以被叫做 Vuex5 ,因?yàn)樗Y(jié)合

    2024年02月07日
    瀏覽(283)
  • Vue3狀態(tài)管理庫(kù)Pinia——自定義持久化插件

    Vue3狀態(tài)管理庫(kù)Pinia——自定義持久化插件

    個(gè)人簡(jiǎn)介 ?? 個(gè)人主頁(yè): 前端雜貨鋪 ???♂? 學(xué)習(xí)方向: 主攻前端方向,正逐漸往全干發(fā)展 ?? 個(gè)人狀態(tài): 研發(fā)工程師,現(xiàn)效力于中國(guó)工業(yè)軟件事業(yè) ?? 人生格言: 積跬步至千里,積小流成江海 ?? 推薦學(xué)習(xí):??前端面試寶典 ??Vue2 ??Vue3 ??Vue2/3項(xiàng)目實(shí)戰(zhàn) ??Node.js??

    2024年02月13日
    瀏覽(28)
  • vue2(Vuex)、vue3(Pinia)、react(Redux)狀態(tài)管理

    vue2(Vuex)、vue3(Pinia)、react(Redux)狀態(tài)管理

    Vuex 是一個(gè)專(zhuān)為 Vue.js應(yīng)用程序開(kāi)發(fā)的狀態(tài)管理模式。它使用集中式存儲(chǔ)管理應(yīng)用的所有組件的狀態(tài),以及規(guī)則保證狀態(tài)只能按照規(guī)定的方式進(jìn)行修改。 State(狀態(tài)) :Vuex 使用單一狀態(tài)樹(shù),即一個(gè)對(duì)象包含全部的應(yīng)用層級(jí)狀態(tài)。這個(gè)狀態(tài)樹(shù)對(duì)應(yīng)著一個(gè)應(yīng)用中的所有狀態(tài)。 Gett

    2024年01月23日
    瀏覽(26)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包