動(dòng)態(tài)創(chuàng)建form表單,網(wǎng)上有插件 (form-create)
不過我不知道它怎么用,沒有使用成功,如果你使用成功了,歡迎下方留言.
最后我使用了笨方法,針對(duì)各個(gè)表單寫好通用的組件,然后根據(jù)type用v-if來渲染對(duì)應(yīng)的表單,數(shù)據(jù),事件什么的都可以動(dòng)態(tài)的傳進(jìn)去,比較好用
<el-form size="mini" class="lj-form lj-form-s1"> <div v-for="(item,i) in table.customerList" :key="i"> <!-- 0單行文本 --> <el-form-item :label="item.field_title + ': '" v-if="item.field_type == '0' && item.is_show == '1'" > <el-input v-model="item.value" :placeholder="item.placeholder"></el-input> </el-form-item> <!-- 3下拉菜單 --> <el-form-item :label="item.field_title + ': '" v-if="item.field_type == '3' && item.is_show == '1'" > <el-select v-model="item.value" :placeholder="item.placeholder"> <span v-for="(item1,i) in item.field_value" :key="i"> <el-option :label="item1" :value="item1"></el-option> </span> </el-select> </el-form-item> </div> </el-form>
動(dòng)態(tài)生成表格的行和列,主要是要求后端返回的數(shù)據(jù)格式,根據(jù)數(shù)據(jù)來動(dòng)態(tài)渲染
注意點(diǎn):這里兩個(gè)數(shù)組 : 表格字段數(shù)據(jù): titleData: [], 表格詳細(xì)數(shù)據(jù): tables: [], 數(shù)據(jù)通過字段來查找/渲染成表格的
<template> <div class="boxShadow"> <div style="margin-top: 20px"> <el-table :data="tables" ref="multipleTable" tooltip-effect="dark" style="width: 100%" @selection-change='selectArInfo'> <el-table-column type="selection" width="45px"></el-table-column> <el-table-column label="序號(hào)" width="62px" type="index"> </el-table-column> <template v-for='(col) in titleData'> <el-table-column sortable :show-overflow-tooltip="true" :prop="col.dataItem" :label="col.dataName" :key="col.dataItem" width="124px"> </el-table-column> </template> <el-table-column label="操作" width="80" align="center"> <template slot-scope="scope"> <el-button size="mini" class="del-com" @click="delTabColOne()" ><i class="iconfont icon-shanchu"></i></el-button> </template> </el-table-column> </el-table> </div> </div> </template> data () { return { tables: [{ xiaoxue: '福蘭', chuzhong: '加芳', gaozhong: '蒲廟', daxue: '西安', yanjiusheng: '西安', shangban: '北京' }, { xiaoxue: '南坊', chuzhong: '禮泉', gaozhong: '禮泉', daxue: '西安', yanjiusheng: '西安', shangban: '南坊' }, ], titleData: [{ dataItem: 'xiaoxue', dataName: '小學(xué)' }, { dataItem: 'chuzhong', dataName: '初中' }, { dataItem: 'gaozhong', dataName: '高中' }, { dataItem: 'daxue', dataName: '大學(xué)' }, { dataItem: 'yanjiusheng', dataName: '研究生' }, { dataItem: 'shangban', dataName: '上班' }] }
總結(jié)
以上所述是小編給大家介紹的vue+element創(chuàng)建動(dòng)態(tài)的form表單及動(dòng)態(tài)生成表格的行和列,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com