代码拉取完成,页面将自动刷新
import { computed, isRef, unref } from "vue";
import { getByPath, setByPath } from "./pathUtil";
import {WrapConfigType} from './types.ts'
export function buildModelValue(configStd:WrapConfigType) {
//Add modelValue if modelValue is configured
function tryApplyModelValue(all: any) {
if ( !configStd ||unref(configStd) == undefined){
return
}
//获取configStd可能的配置
tryApplyModelValueInternal(all,configStd)
//Check whether there is ~mvs
const mvs=unref(unref(configStd)['~mvs'])
if(!mvs||!Array.isArray(mvs)||mvs.length==0){
return
}
//
for(const c of mvs){
tryApplyModelValueInternal(all,c)
}
}
//
return {tryApplyModelValue };
}
//
function tryApplyModelValueInternal(all: any, configSingle: any) {
//whether modelValue is configured.If not, do not build modelValue otherwise it may have unexpected result
if (
!configSingle ||
unref(configSingle) == undefined ||
! (unref(configSingle).hasOwnProperty("~modelValue"))
) {
return;
}
//modelValue
const modelValue = computed({
get() {
let modelValuePath = unref(configSingle)["~modelValuePath"];
if (modelValuePath) {
return getByPath(
unref(unref(configSingle)["~modelValue"]),
modelValuePath
);
} else {
return unref(unref(configSingle)["~modelValue"]);
}
},
set(valueNew) {
//
let modelValuePath = unref(configSingle)["~modelValuePath"];
if (modelValuePath) {
setByPath(
unref(unref(configSingle)["~modelValue"]),
modelValuePath,
valueNew
);
} else {
if (isRef(unref(configSingle)["~modelValue"])) {
unref(configSingle)["~modelValue"].value = valueNew;
} else {
unref(configSingle)["~modelValue"] = valueNew;
}
}
},
});
//modelValueName
const modelValueName = computed(() => {
//
return unref(configSingle)["~modelValueName"] || "modelValue";
});
//Add model value related properties
all[modelValueName.value] = modelValue.value,
all["onUpdate:" + modelValueName.value] = (value: any) => {
modelValue.value = value;
}
//
return modelValue
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。