21 lines
592 B
Plaintext
21 lines
592 B
Plaintext
import { defineStore } from 'pinia';
|
|
|
|
export const useMyStore = defineStore('myStore', {
|
|
state: () => ({
|
|
data: JSON.parse(localStorage.getItem('myData')) || null,
|
|
type: JSON.parse(localStorage.getItem('mType')) || null,
|
|
}),
|
|
actions: {
|
|
setData(data: any) {
|
|
this.data = data;
|
|
// 将数据保存到本地存储
|
|
localStorage.setItem('myData', JSON.stringify(data));
|
|
},
|
|
setType(data: any) {
|
|
this.type = data;
|
|
// 将数据保存到本地存储
|
|
localStorage.setItem('myType', JSON.stringify(data));
|
|
},
|
|
},
|
|
|
|
}); |