You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
742 B
TypeScript
34 lines
742 B
TypeScript
import { defineStore } from 'pinia'
|
|
|
|
export const useSharedDataStore = defineStore('sharedData', {
|
|
state: () => ({
|
|
// 定义需要共享的数据
|
|
dynamicValue: null,
|
|
// 可以定义多个共享状态
|
|
otherData: '',
|
|
// 可以添加时间戳以便监听更新
|
|
lastUpdated: null
|
|
}),
|
|
|
|
actions: {
|
|
// 更新数据的方法
|
|
updateDynamicValue(value) {
|
|
this.dynamicValue = value
|
|
this.lastUpdated = new Date().toISOString()
|
|
},
|
|
|
|
// 清空数据
|
|
clearData() {
|
|
this.dynamicValue = null
|
|
this.otherData = ''
|
|
}
|
|
},
|
|
|
|
getters: {
|
|
// 可以添加计算属性
|
|
formattedValue() {
|
|
return this.dynamicValue ? JSON.stringify(this.dynamicValue) : '无数据'
|
|
}
|
|
}
|
|
})
|