组件结构
2024年1月9日大约 1 分钟
组件结构
在新建组件时,需要按照指定的配置和规则进行打包,且组件中必须存在 config.json 、 index.js 。
|-- Text // 演示demo
|-- config.json // 组件配置(必须)
|-- index.js // 组件导出(必须)
|-- mobile
| |-- index.vue
|-- pc
| |-- index.vue
|-- sub // 子表单组件
|-- index.vue组件中需要添加的文件:
config.json:组件配置文件(查看详情)index.js: 组件导出,由于在设计器加载组件是时通过请求js动态注入到html中的方式进行加载的,所以在打包是会将所有资源打包到一个js文件中。
// index.js
import PC from "./pc/index.vue";
import Mobile from "./mobile/index.vue";
import Sub from "./sub/index.vue";
import {
version,
compatibleSdkVersion
} from "./config.json";
export default {
PC,
Mobile,
Sub,
version: version,
compatibleSdkVersion: compatibleSdkVersion,
};index.js导出属性说明:
PC:PC端显示组件。
Mobile:移动端显示组件。Sub:PC子表单中的组件,Sub属性并不是必须的,当
version:组件版本,必须和config.json中config.json中不存在属性supportSubforms或者该属性为false,则表示该组件不支持子表单;由于PC端表单组件在子表单中渲染样式和交互都存在一定的差异,所以在PC端需要单独导出子表单组件;而移动端表单组件在子表单中和页面中渲染的组件为同一套,则不需要导出子表单组件。version一致,注意每次迭代版本必须更新版本。
compatibleSdkVersion:组件支持的设计器版本(例如:>=1.0.0, <=1.5.1)。
以上则是导出规范。
提示
以红色星号标记的表示必须存在的属性。不可缺少
