Ai
1 Star 2 Fork 1

旻天信息/mttk-vue-wrap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
compBaseProp.ts 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
旻天信息 提交于 2024-05-14 09:26 +08:00 . Update license
import { computed, unref } from "vue";
//Props,use computed to avoid evaluate each time render is called
export function buildProps(contextWrapper, configStd) {
return computed(() => {
//If component is function ,wrap all the props into config prop
let component = configStd.value["~component"] || configStd.value["~"];
if (typeof component == "function") {
return { config: configStd.value };
}
//
const result = {};
//
for (const key of Object.keys(configStd.value)) {
// if (
// key.startsWith("~") ||
// key.startsWith("!")||
// key.startsWith("@") ||
// key.startsWith("#") ||
// key.startsWith("$") ||
// key.startsWith("^")
// ) {
// continue;
// }
if(!/^[A-Za-z]/.test(key.charAt(0))){
//If it is not started with letter, ignore
continue;
}
//please note,unref is used here
result[key] = unref(configStd.value[key]);
//style
handlePossibleStyle(result)
//class
handlePossibleClass(result)
}
//
return result;
})}
function handlePossibleStyle(result){
const style=result['style']
if(typeof style!='object'){
return
}
//
const resultStyle={}
//
for(const key of Object.keys(style)){
const value=style[key]
//try to eval value if needed
resultStyle[key]=unref(value)
}
//
result['style']=resultStyle
}
function handlePossibleClass(result){
const classDefined=result['class']
if(!Array.isArray(classDefined)){
return
}
//
const resultClass=[]
//
for(const value of classDefined){
resultClass.push(unref(value))
}
//
result['class']=resultClass
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/jamie0828/mttk-vue-wrap.git
git@gitee.com:jamie0828/mttk-vue-wrap.git
jamie0828
mttk-vue-wrap
mttk-vue-wrap
master

搜索帮助