添加订阅事件监听
This commit is contained in:
@ -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 }
|
||||
})
|
||||
Reference in New Issue
Block a user