首页 > 其他分享 >pinia-状态管理的修改

pinia-状态管理的修改

时间:2023-06-19 19:23:21浏览次数:47  
标签:piniaAge 状态 pinia .. piniaStore actions 修改 storeA

一、直接修改

import { storeA } from '../../piniaStore/storeA';

let piniaStore_storeA = storeA();

//将piniaAge状态修改为18

piniaStore_storeA.piniaAge = 18

 

二、$patch修改

piniaStore_storeA.$patch({ piniaAge: 15, piniaName: 'danguner' })//普通修改

piniaStore_storeA.$patch((state) => { state.piniaAge = 25 state.piniaName = '小七' })//函数修改

 

三、在actions中进行修改

前提在actions里有相关函数:

actions: { edit_name (data) { this.piniaName = data }, },

页面调用:

import { storeA } from '../../piniaStore/storeA';

let piniaStore_storeA = storeA();

piniaStore_storeA.edit_name("小红")//通过edit_name将小红传入修改

标签:piniaAge,状态,pinia,..,piniaStore,actions,修改,storeA
From: https://www.cnblogs.com/Dasate/p/17491977.html

相关文章