


VUE makes a form with data collection, verification and submission functions
Jun 04, 2018 pm 03:17 PMThis time I will bring you VUE to make a form with data collection, verification and submission functions. What are the things to pay attention to when VUE makes a form with data collection, verification and submission functions? The following is a practical case, let’s take a look. Sample
https://raw.githubusercontent.com/xaboy/form-create/dev/images/sample110.jpg
npm?install?form-create
git?clone?https://github.com/xaboy/form-create.git
cd?form-create
npm?install
<!-- import Vue -->
<script src="node_modules/vue/dist/vue.min.js"></script>
<!-- import iview -->
<link rel="stylesheet" href="node_modules/iview/dist/styles/iview.css" rel="external nofollow" >
<script src="node_modules/iview/dist/iview.min.js"></script>
<!-- 省市區(qū)三級聯(lián)動json數(shù)據(jù) -->
<script src="/district/province_city_area.js"></script>
<!-- 模擬數(shù)據(jù) -->
<script src="mock.js"></script>
<!-- import formCreate -->
<script src="dist/form-create.min.js"></script>
Attention! iview version please> =2.9.2, otherwise there may be problems
let?rules?=?window.mock;
new?Vue({
?mounted:function(){
?let?$f?=?this.$formCreate(mock,
???{
????onSubmit:function?(formData)?{
?????console.log(formData);
?????$f.submitStatus({loading:true});
???}
??});
??//動態(tài)添加表單元素
??$f.append($r,'goods_name');
?}
})
$formCreate parameters
- options Initialization configuration parameters (see createOptions at the bottom for details)
- $f Instance method
- formData() Get the value of the form
- getValue(field) Get the value of the specified field
- changeField( field, value) Modify the value of the specified field
- resetFields() Reset the form
- destroy() Destroy the form
- removeField(field) Delete the specified field
- fields() Get the names of all fields in the form
- submit() Form verification After passing the form, submit the form and trigger the onSubmit event
##validate(successFn,errorFn) form verification. If the verification passes, execute successFn. If it fails, execute errorFn
validateField(field,callback) Form validation specifies the field
-
?$f.validateField(field,(errMsg)=>{ ??if(errMsg){ ???//TODO?驗證未通過 ??}else{ ???//TODO?驗證通過 ??} ?});
prepend(rule,field = undefined) Enter the specified form element before the field field, no If the field is passed in, it will be placed in the first one by default.
$f.prepend({ ??type:"input", ??title:"商品簡介", ??field:"goods_info", ??value:"", ??props:?{ ???"type":?"text", ???"placeholder":?"請輸入商品簡介", ??}, ??validate:[ ???{?required:?true,?message:?'請輸入商品簡介',?trigger:?'blur'?}, ??], ?});
$f.append({ ??type:"input", ??title:"商品簡介", ??field:"goods_info", ??value:"", ??props:?{ ???"type":?"text", ???"placeholder":?"請輸入商品簡介", ??}, ??validate:[ ???{?required:?true,?message:?'請輸入商品簡介',?trigger:?'blur'?}, ??], ?});
btn.loading() let The form submission button enters the loading state- btn.finish() returns the form submission button to its normal state
rules Form element rules
- hidden hidden field
$f.submitStatus({ ??//按鈕類型,可選值為primary、ghost、dashed、text、info、success、warning、error或者不設置 ??type:"primary", ??//按鈕大小,可選值為large、small、default或者不設置 ??size:"large", ??//按鈕形狀,可選值為circle或者不設置 ??shape:undefined, ??//開啟后,按鈕的長度為?100% ??long:true, ??//設置button原生的type,可選值為button、submit、reset ??htmlType:"button", ??//設置按鈕為禁用狀態(tài) ??disabled:false, ??//設置按鈕的圖標類型 ??icon:"ios-upload", ??//按鈕文字提示 ??innerText:"提交", ??//設置按鈕為加載中狀態(tài) ??loading:false ?})
input input box
hiddenRule: { ?type:"hidden",//必填! ?//字段名稱 ?field:"id",?//必填! ?//input值 ?value:"14"?//必填! }validate form validation rules, please view the specific configuration: https://github.com/yiminghe/async-validator
radio radio button
inputRule?: { ??type:"input",//必填!? ??//label名稱 ??title:"商品名稱",//必填! ??//字段名稱 ??field:"goods_name",//必填! ??//input值 ??value:"iphone?7", ??props:?{ ???//輸入框類型,可選值為?text、password、textarea、url、email、date ???"type":?"text",?//必填! ???//是否顯示清空按鈕 ???"clearable":false,? ???//設置輸入框為禁用狀態(tài) ???"disabled":?false,? ???//設置輸入框為只讀 ???"readonly":?false, ???//文本域默認行數(shù),僅在?textarea?類型下有效 ???"rows":?4,? ???//自適應內(nèi)容高度,僅在?textarea?類型下有效,可傳入對象,如?{?minRows:?2,?maxRows:?6?} ???"autosize":?false,? ???//將用戶的輸入轉(zhuǎn)換為?Number?類型 ???"number":?false,? ???//自動獲取焦點 ???"autofocus":?false,? ???//原生的自動完成功能,可選值為?off?和?on ???"autocomplete":?"off",? ???//占位文本 ???"placeholder":?"請輸入商品名稱",? ???//輸入框尺寸,可選值為large、small、default或者不設置 ???"size":?"default", ???//原生的?spellcheck?屬性 ???"spellcheck":?false, ??}, ??event:{ ???//按下回車鍵時觸發(fā) ???enter:(event)=>{}, ???//設置?icon?屬性后,點擊圖標時觸發(fā) ???click:(event)=>{}, ???//數(shù)據(jù)改變時觸發(fā) ???change:(event)=>{}, ???//輸入框聚焦時觸發(fā) ???focus:(event)=>{}, ???//輸入框失去焦點時觸發(fā) ???blur:(event)=>{}, ???//原生的?keyup?事件 ???keyup:(event)=>{}, ???//原生的?keydown?事件 ???keydown:(event)=>{}, ???//原生的?keypress?事件 ???keypress:(event)=>{}, ??}, ??validate:[ ???{?required:?true,?message:?'請輸入goods_name',?trigger:?'blur'?}, ??], ?}
checkbox checkbox
radioRule?: { ??type:"radio",//必填! ??//label名稱 ??title:"是否包郵",//必填! ??//字段名稱 ??field:"is_postage",//必填! ??//input值 ??value:"0", ??//可選參數(shù) ??options:[ ???{value:"0",label:"不包郵",disabled:false}, ???{value:"1",label:"包郵",disabled:true}, ??],//必填! ??props:?{ ???//可選值為?button?或不填,為?button?時使用按鈕樣式 ???"type":undefined,? ???//單選框的尺寸,可選值為?large、small、default?或者不設置 ???"size":"default",? ???//是否垂直排列,按鈕樣式下無效 ???"vertical":false,? ??}, ??event:{ ???//在選項狀態(tài)發(fā)生改變時觸發(fā),返回當前狀態(tài)。通過修改外部的數(shù)據(jù)改變時不會觸發(fā) ???change:(...arg)=>{}, ??}, ??validate:[], ?}
select selector
checkboxRule?: { ??type:"checkbox",//必填! ??//label名稱 ??title:"標簽",//必填! ??//字段名稱 ??field:"label",//必填! ??//input值 ??value:[ ???"1","2","3" ??], ??//可選參數(shù) ??options:[ ???{value:"1",label:"好用",disabled:true}, ???{value:"2",label:"方便",disabled:false}, ???{value:"3",label:"實用",disabled:false}, ???{value:"4",label:"有效",disabled:false}, ??],//必填! ??props:?{ ???//多選框組的尺寸,可選值為?large、small、default?或者不設置 ???"size":"default",? ??}, ??event:{ ???//只在單獨使用時有效。在選項狀態(tài)發(fā)生改變時觸發(fā),通過修改外部的數(shù)據(jù)改變時不會觸發(fā) ???change:(...arg)=>{}, ??}, ??validate:[], ?}
switch switch
selectRule?: { ??type:?"select",//必填! ??field:?"cate_id",//必填! ??title:?"產(chǎn)品分類",//必填! ??//input值 ??value:?["104","105"], ??//可選參數(shù) ??options:?[ ???{"value":?"104",?"label":?"生態(tài)蔬菜",?"disabled":?false}, ???{"value":?"105",?"label":?"新鮮水果",?"disabled":?false}, ??],//必填! ??props:?{ ????//是否支持多選 ???"multiple":?true,? ???//是否可以清空選項,只在單選時有效 ???"clearable":?false, ???//是否支持搜索 ???"filterable":?true,? ???//?暫不支持遠程搜索 ???//?"remote":?false,?//是否使用遠程搜索 ???//?"remote-method":Function,?//遠程搜索的方法 ???//?"loading":?false,?//當前是否正在遠程搜索 ???//?"loading-text":?"加載中",?//遠程搜索中的文字提示 ???//選擇框大小,可選值為large、small、default或者不填 ???"size":"default",? ???//選擇框默認文字 ???"placeholder":?"請選擇",? ????//當下拉列表為空時顯示的內(nèi)容 ???"not-found-text":?"無匹配數(shù)據(jù)", ???//彈窗的展開方向,可選值為?bottom?和?top ???"placement":?"bottom",? ???//是否禁用 ???"disabled":?false,? ??}, ??event:{ ???//選中的Option變化時觸發(fā),返回?value ???change:(checked)=>{}, ???//搜索詞改變時觸發(fā) ???'query-change':(keyword)=>{}, ??}, ??validate:[], ?}
DatePicker Date Picker
switchRule?: { ??type:"switch",//必填! ??//label名稱 ??title:"是否上架",//必填! ??//字段名稱 ??field:"is_show",//必填! ??//input值 ??value:"1", ??props:?{ ???//開關的尺寸,可選值為large、small、default或者不寫。建議開關如果使用了2個漢字的文字,使用?large。 ???"size":"default",? ???//禁用開關 ???"disabled":false, ???//選中時的值,當使用類似?1?和?0?來判斷是否選中時會很有用 ???"trueValue":"1",? ???//沒有選中時的值,當使用類似?1?和?0?來判斷是否選中時會很有用 ???"falseValue":"0",? ??}, ??slot:?{ ???//自定義顯示打開時的內(nèi)容 ???open:"上架",? ???//自定義顯示關閉時的內(nèi)容 ???close:"下架",? ??}, ??event:{ ???//開關變化時觸發(fā),返回當前的狀態(tài)?0?|?1 ???change:(bool)=>{}, ??}, ??validate:[], ?}TimePicker Time Picker
TimePickerRule?: { ??type:?"TimePicker",//必填! ??field:?"section_time",//必填! ??title:?"活動時間",//必填! ??//input值,?type為timerange?value為數(shù)組?[start_value,end_value] ??value:?[],? ??props:?{ ???//顯示類型,可選值為?time、timerange ???"type":?"timerange",?//必填! ???//展示的時間格式 ???"format":?"HH:mm:ss",? ???//下拉列表的時間間隔,數(shù)組的三項分別對應小時、分鐘、秒。例如設置為?[1,?15]?時,分鐘會顯示:00、15、30、45。 ???"steps":?[],? ???//時間選擇器出現(xiàn)的位置,可選值為toptop-starttop-endbottombottom-startbottom-endleftleft-startleft-endrightright-startright-end ???"placement":?"bottom-start",? ???//占位文本 ???"placeholder":"請選擇獲得時間",? ???//是否顯示底部控制欄,開啟后,選擇完日期,選擇器不會主動關閉,需用戶確認后才可關閉 ???"confirm":false,? ???//尺寸,可選值為large、small、default或者不設置 ???"size":"default", ???//是否禁用選擇器 ???"disabled":false,? ???//是否顯示清除按鈕 ???"clearable":true,? ???//完全只讀,開啟后不會彈出選擇器 ???"readonly":false,? ???//文本框是否可以輸入 ???"editable":false,? ??}, ??event:{ ???//時間發(fā)生變化時觸發(fā)?已經(jīng)格式化后的時間,比如?09:41:00 ???change:(checked)=>{}, ???//彈出浮層和關閉浮層時觸發(fā)?true?|?false ???'open-change':(bool)=>{}, ???//在清空日期時觸發(fā) ???clear:(...arg)=>{}, ??}, ??validate:[], ?}ColorPicker Color Picker
InputNumberRule?: { ??type:?"InputNumber",//必填! ??field:?"sort",//必填! ??title:?"排序",//必填! ??//input值 ??value:?1, ??props:?{ ???//最大值 ???"max":?undefined,? ???//最小值 ???"min":?undefined,? ???//每次改變的步伐,可以是小數(shù) ???"step":?1,? ???//輸入框尺寸,可選值為large、small、default或者不填 ???"size":"default",? ???//設置禁用狀態(tài) ???"disabled":false,? ???//是否設置為只讀 ???"readonly":false,? ???//是否可編輯 ???"editable":true,? ???//數(shù)值精度 ???"precision":0,? ??}, ??event:{ ???//數(shù)值改變時的回調(diào),返回當前值 ???change:(value)=>{}, ???//聚焦時觸發(fā) ???focus:(event)=>{}, ???//失焦時觸發(fā) ???blur:(event)=>{}, ??}, ??validate:[], ?}
Cascader Multi-level linkage
ColorPickerRule?: { ??type:?"ColorPicker",//必填! ??field:?"color",//必填! ??title:?"顏色",//必填! ??//input值 ??value:?'#ff7271',? ??props:?{ ???//是否支持透明度選擇 ???"alpha":?false,? ???//是否支持色彩選擇 ???"hue":?true,? ???//是否顯示推薦的顏色預設 ???"recommend":?false,? ???//尺寸,可選值為large、small、default或者不設置 ???"size":"default",? ???//自定義顏色預設 ???"colors":[],? ???//顏色的格式,可選值為?hsl、hsv、hex、rgb,開啟?alpha?時為?rgb,其它為?hex ???"format":"hex",? ??}, ??event:{ ???//當綁定值變化時觸發(fā),返回當前值 ???change:(color)=>{}, ???//聚焦時觸發(fā)?面板中當前顯示的顏色發(fā)生改變時觸發(fā) ???'active-change':(color)=>{}, ??}, ??validate:[], ?}
Upload Upload
CascaderRule: { ??type:"cascader",//必填! ??title:"所在區(qū)域",//必填! ??field:"address",//必填! ??//input值 ??value:['陜西省','西安市','新城區(qū)'], ??props:{ ???//可選項的數(shù)據(jù)源,格式參照示例說明 ???data:window.province?||?[],//必填! ???//選擇后展示的函數(shù),用于自定義顯示格式 ???renderFormat:label?=>?label.join('?/?'), ???//是否禁用選擇器 ???disabled:false, ???//是否支持清除 ???clearable:true, ???//輸入框占位符 ???placeholder:'請選擇', ???//次級菜單展開方式,可選值為?click?或?hover ???trigger:'click', ???//當此項為?true?時,點選每級菜單選項值都會發(fā)生變化,具體見上面的示例 ???changeOnSelect:false, ???//輸入框大小,可選值為large和small或者不填 ???size:undefined, ???//動態(tài)獲取數(shù)據(jù),數(shù)據(jù)源需標識?loading ???loadData:()=>{}, ???//是否支持搜索 ???filterable:false, ???//當搜索列表為空時顯示的內(nèi)容 ???notFoundText:'無匹配數(shù)據(jù)', ???//是否將彈層放置于?body?內(nèi),在?Tabs、帶有?fixed?的?Table?列內(nèi)使用時,建議添加此屬性,它將不受父級樣式影響,從而達到更好的效果 ???transfer:false, ??}, ??event:{ ???//選擇完成后的回調(diào),返回值?value?即已選值?value,selectedData?為已選項的具體數(shù)據(jù) ???change:(value,?selectedData)=>{}, ???//展開和關閉彈窗時觸發(fā) ???'visible-change':bool=>{} ??}, ??validate:[], ?}accept File type: https://developer.mozilla.org/en-US /docs/Web/HTML/Element/input#attr-accept
Global configuration createOptions
UploadRule?: { ??type:?"Upload",//必填! ??field:?"pic",//必填! ??title:?"輪播圖",//必填! ??//input值,當maxLength等與1時值為字符串,大于1時值為數(shù)組 ??value:?['http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg','http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg'],?//input值 ??props:?{ ???//上傳控件的類型,可選值為?select(點擊選擇),drag(支持拖拽) ???"type":"select",?//必填! ???//上傳文件類型,可選值為?image(圖片上傳),file(文件上傳) ???"uploadType":"image",?//必填! ???//上傳的地址 ???"action":?"",?//必填!? ???//上傳的文件字段名 ???"name":"",? ???//上傳時附帶的額外參數(shù) ???"data":{},? ???//設置上傳的請求頭部 ???"headers":?{},? ???//是否支持多選文件 ???"multiple":?true, ???//支持發(fā)送?cookie?憑證信息 ???"withCredentials":false,? ???//不支持 ???//?"showUploadList":false,?//是否顯示已上傳文件列表 ???//?"defaultFileList":[],?//?默認已上傳的文件列表 ???//接受上傳的文件類型 ???"accept":"", ???//支持的文件類型,與?accept?不同的是,format?是識別文件的后綴名,accept?為?input?標簽原生的?accept?屬性,會在選擇文件時過濾,可以兩者結(jié)合使用 ???"format":[],? ???//文件大小限制,單位?kb ???"maxSize":undefined,? ???//可上傳文件數(shù)量 ???"maxLength":1, ???//上傳文件之前的鉤子,參數(shù)為上傳的文件,若返回?false?或者?Promise?則停止上傳 ???"beforeUpload":()=>{},? ???//文件上傳時的鉤子,返回字段為?event,?file,?fileList ???"onProgress":()=>{},? ???//文件上傳成功時的鉤子,返回字段為?response,?file,?fileList,若需有把文件添加到文件列表中,在函數(shù)值返回即可 ???"onSuccess":function?()?{ ????return?'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg'; ???},?//必填! ???//文件上傳失敗時的鉤子,返回字段為?error,?file,?fileList ???"onError":(error,?file,?fileList)=>{},? ???//點擊已上傳的文件鏈接時的鉤子,返回字段為?file,?可以通過?file.response?拿到服務端返回數(shù)據(jù) ???"onPreview":()=>{},? ???//文件列表移除文件時的鉤子,返回字段為?file,?fileList ???"onRemove":()=>{},? ???//文件格式驗證失敗時的鉤子,返回字段為?file,?fileList ???"onFormatError":()=>{},? ???//文件超出指定大小限制時的鉤子,返回字段為?file,?fileList ???"onExceededSize":()=>{},? ???//輔助操作按鈕的圖標?,設置為false將不顯示 ???handleIcon:'ionic', ???//點擊輔助操作按鈕事件 ???onHandle:(src)=>{}, ???//是否可刪除,設置為false是不顯示刪除按鈕 ???allowRemove:true, ??}, ?}I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other php Chinese websites related articles!
Recommended reading:
How to use Vue to operate DIV
##Use Node.js to convert file encoding formats
The above is the detailed content of VUE makes a form with data collection, verification and submission functions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

If you need to know how to use filtering with multiple criteria in Excel, the following tutorial will guide you through the steps to ensure you can filter and sort your data effectively. Excel's filtering function is very powerful and can help you extract the information you need from large amounts of data. This function can filter data according to the conditions you set and display only the parts that meet the conditions, making data management more efficient. By using the filter function, you can quickly find target data, saving time in finding and organizing data. This function can not only be applied to simple data lists, but can also be filtered based on multiple conditions to help you locate the information you need more accurately. Overall, Excel’s filtering function is a very practical

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.
