Vuex 的專案例項4 新增事項

2022-06-08 02:09:11 字數 662 閱讀 4034

1、給新增事項按鈕增加點選事件:

<

a-button

type

="primary"

@click

="additemtolist"

>新增事項

a-button

>

<

script

>

import from

'vuex

'export

default

this

.$store.commit(

'additem',

this

.inputvalue)}}}

script

>

2、開啟 store/index.js 檔案,新增變數 nextid 及 additem :

state: ,

mutations:

state.list.push(obj)

state.nextid++state.inputvalue = ''}

}

此時點選新增事件按鈕,會把檔案框中的內容,新增到 list 列表中。

Vuex的簡單例項 4

1 你可以在元件中使用 this.store.commit 提交 mutation,或者使用 mapmutations 輔助函式將元件中的 methods 對映為 store.commit 呼叫。看之前文章中的 修改密碼狀態 store.js mutations login.vue methods ...

vuex的使用例項

一 store資料倉儲位置 二 store user.js 僅關於使用者註冊的資料 import vue from vue export const user signin user signin 登入成功 export const user signout user signout 退出登入 ex...

Vuex 的專案例項1 專案初始化

npm install vuex axios ant design vue s 當然也可以使用視覺化面板的依賴安裝。ant design vue 是ui元件庫。main.js 檔案 1.匯入 ant destign vue 元件庫 import antd from ant design vue 2....