fix:store数据绑定
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {IPageComponent} from '@/type/IPageComponent';
|
||||
import {ref} from 'vue';
|
||||
|
||||
function findObjectById(obj, targetId) {
|
||||
if (Array.isArray(obj)) {
|
||||
@ -22,28 +21,27 @@ function findObjectById(obj, targetId) {
|
||||
return null; // 如果没有找到,则返回null
|
||||
}
|
||||
|
||||
export const useSchemeStore = defineStore('scheme', () => {
|
||||
const components = ref<IPageComponent[]>()
|
||||
const previewScheme = ref<IPageComponent[]>()
|
||||
const nowComponentsData = ref<IPageComponent>()
|
||||
export const useSchemeStore = defineStore('scheme', {
|
||||
state: () => ({
|
||||
components: [],
|
||||
previewScheme: [],
|
||||
nowComponentsData: {}
|
||||
}),
|
||||
actions:
|
||||
{
|
||||
initPreviewScheme(value) {
|
||||
this.previewScheme = value
|
||||
this.nowComponentsData = value[0]
|
||||
},
|
||||
initComponents(value) {
|
||||
this.components = value
|
||||
},
|
||||
getSchemeObj(id) {
|
||||
return findObjectById(this.previewScheme, id)
|
||||
},
|
||||
updateScheme() {
|
||||
|
||||
function initPreviewScheme(value) {
|
||||
previewScheme.value = value
|
||||
nowComponentsData.value=value[0]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function initComponents(value:IPageComponent[]) {
|
||||
components.value = value
|
||||
}
|
||||
|
||||
function getSchemeObj(id) {
|
||||
return findObjectById(previewScheme.value, id)
|
||||
}
|
||||
|
||||
function updateScheme() {
|
||||
|
||||
}
|
||||
|
||||
return {previewScheme, components, nowComponentsData, initComponents, initPreviewScheme, getSchemeObj, updateScheme}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user