添加订阅事件监听

This commit is contained in:
lhj
2024-10-04 21:18:22 +08:00
parent a4f2f020fc
commit b813c09edd
7 changed files with 86 additions and 31 deletions

View File

@ -1,22 +1,33 @@
import { defineStore } from 'pinia'
import { IPageComponent } from '../type/IPageComponent';
import { ref,computed } from 'vue';
import { ref } from 'vue';
export const useSchemeStore = defineStore('counter', () => {
const count = ref(0)
const scheme=ref<IPageComponent>()
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
function findObjectById(obj, targetId) {
if (Array.isArray(obj)) {
for (let item of obj) {
let found = findObjectById(item, targetId);
if (found) return found;
}
} else if (typeof obj === 'object' && obj !== null) {
if (obj.id === targetId) {
return obj;
}
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
let found = findObjectById(obj[key], targetId);
if (found) return found;
}
}
}
function decrement() {
count.value--
return null; // 如果没有找到则返回null
}
export const useSchemeStore = defineStore('scheme', () => {
const scheme = ref<IPageComponent[]>()
function initScheme(value) {
scheme.value = value
}
function initScheme(value)
{
scheme.value=value
function getSchemeObj(id) {
return findObjectById(scheme.value, id)
}
return { count,scheme, doubleCount, increment,decrement,initScheme }
return { scheme, initScheme, getSchemeObj }
})