[TOC]
安装VForm
方法一:
npm i vform-builds
或yarn add vform-builds
注意:VForm依赖Element UI,需要先安装Element UI。
npm i element-ui
或yarn add element-ui
方法二:
CDN引入,适合直接在HTML中使用组件。
- git克隆VFormBuilds:https://gitee.com/vdpadmin/VFormBuilds
- 把dist目录下6个文件上传到Web服务器或CDN;
在HTML中引入js和css,如下所示:
- 在HTML中使用表单设计器组件VFormDesigner ```html <!DOCTYPE html>
2. 在HTML中使用表单渲染器组件VFormRender
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<title>VForm Demo</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.7/theme-chalk/index.min.css">
<link rel="stylesheet" href="VFormRender.css?t=20210730"> <!-- 根据Web服务器或CDN路径修改 -->
<style type="text/css">
</style>
</head>
<body>
<div id="app">
<v-form-render :form-json="formJson" :form-data="formData" :option-data="optionData" ref="vFormRef">
</v-form-render>
<el-button type="primary" @click="submitForm">Submit</el-button>
</div>
<script type="text/javascript">
if (!!window.ActiveXObject || "ActiveXObject" in window) { //IE load polyfill.js for Promise
var scriptEle = document.createElement("script");
scriptEle.type = "text/javascript";
scriptEle.src = "https://cdn.bootcss.com/babel-polyfill/6.23.0/polyfill.min.js"
document.body.appendChild(scriptEle)
}
</script>
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js"></script>
<script src="https://cdn.staticfile.org/element-ui/2.15.7/index.min.js"></script>
<script src="VFormRender.umd.min.js?t=20210730"></script> <!-- 根据Web服务器或CDN路径修改 -->
<script>
new Vue({
el: '#app',
data: {
formJson: {"widgetList":[],"formConfig":{"labelWidth":80,"labelPosition":"left","size":"","labelAlign":"label-left-align","cssCode":"","customClass":"","functions":"","layoutType":"PC","onFormCreated":"","onFormMounted":"","onFormDataChange":"","onFormValidate":""}},
formData: {},
optionData: {}
},
methods: {
submitForm: function() {
this.$refs.vFormRef.getFormData().then( function(formData) {
// Form Validation OK
alert( JSON.stringify(formData) )
}).catch( function(error) {
// Form Validation Failed
alert(error)
})
}
}
});
</script>
</body>
</html>
安装VForm Pro
VForm Pro相比VForm提供了子表单(sub-form)等高级组件,订阅源码更新服务后,即可获取到VForm Pro源代码。立即订阅==>
Pro订阅用户获取到源码后,需要自己编译打包,具体方法参见《编译打包》。