溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

利用vue如何實(shí)現(xiàn)一個(gè)動(dòng)態(tài)表格提交參數(shù)的功能

發(fā)布時(shí)間:2020-11-10 14:52:06 來源:億速云 閱讀:438 作者:Leah 欄目:開發(fā)技術(shù)

本篇文章給大家分享的是有關(guān)利用vue如何實(shí)現(xiàn)一個(gè)動(dòng)態(tài)表格提交參數(shù)的功能,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

動(dòng)態(tài)控件代碼如下

<el-form
    :model="formData"
    >
    <div v-if="tableshow">
    <div v-for="(item,i) in control" :key="i"  >
     <el-form-item
     v-if="item.type=='input'"
     :key="item.name"
     :prop="item.name"
     label-width="100px">
     <label slot="label">{{ item.cnname }}:</label>
     <el-input v-model="item.value" size="mini" />
     </el-form-item>
     <el-form-item
     v-if="item.type=='time'"
     :key="item.name"
     :prop="item.name"
     label-width="100px">
     <label slot="label">{{ item.cnname }}:</label>
     <el-date-picker
      v-model="item.value"
      value-format="yyyy-MM-dd HH:mm:ss"
      type="date"
      placeholder="選擇日期"/>
     </el-form-item>
    </div>
    <div >
     <el-form-item prop="name" >
     <el-button class="filter-item" type="primary" icon="el-icon-search" size="mini" @click="cmdsearch">
      {{ $t('table.search') }}
     </el-button>
     </el-form-item>
    </div>
    </div>
   </el-form>

data格式如下

 control: [{
  name: 'input1',
  cnname: '輸入框1',
  type: 'input',
  value: '這里'
  }, {
  name: 'time1',
  cnname: '時(shí)間范圍',
  type: 'time',
  value: null
  }]

還要監(jiān)聽所有控件變化

 computed: {
 // 監(jiān)聽所有控件變化
 formData: function() {
  var formData = {}
  this.control.forEach((item) => {
  formData[item.name] = item.value
  })
  return formData
 }
 }

動(dòng)態(tài)表格如下

<el-table
    v-if="tableshow"
    id="exportTab"
    ref="multipleTable"
    :data="tables"
    border="true"
    tooltip-effect="dark"
    
    @selection-change="selectArInfo">
    <el-table-column fixed="left" label="序號(hào)" width="62px" type="index"/>
    <template v-for="(col) in tableData">
    <el-table-column
     :show-overflow-tooltip="true"
     :formatter="fmtLength"
     :prop="col.dataItem"
     :label="col.dataName"
     :key="col.dataItem"
     resizable="true"
     width="120px"/>
    </template>
   </el-table>

需要兩個(gè)數(shù)組,一個(gè)保存表格列名,一個(gè)保存表格數(shù)據(jù)

 tables: [], 
  tableData: [dataItem: xxx,
   dataName: xxx], //保存表格列名

補(bǔ)充知識(shí):vue table表格的使用(動(dòng)態(tài)數(shù)據(jù)展示)

第一種方式

 <el-table :data="tableDataalllist" border  @sort-change="totalusercount">
  <el-table-column :label="head" :prop="head" v-for="(head, index) in header" :key="head" :sortable="定義自定義排序項(xiàng)">
  <template slot-scope="scope">
  {{tableDataalllist[scope.$index][index]}} // 當(dāng)前行數(shù)據(jù) 接收兩個(gè)參數(shù)scope.$index; scope.row
  <template>
  <el-table-column>
 <el-table>
<script>
 export default{
  data(){
   return{
   // 數(shù)據(jù)結(jié)構(gòu)
    tableDataalllist:[{
     1,'張三','23'
    },{
     2,'李四','15'
    },{
     3,'王五','18'
    }],
    header:['id','name','age']
   } 
  },
  methods:{
  // 接受一個(gè)obj參數(shù)
   totalusercount(obj){
    console.log(obj.prop) // 排序規(guī)則
    console.log(obj.order) // 排序方式
   }
  }
 }
</script>
idnameage
1張三23
2李四15
3王五18

第二種方式(動(dòng)態(tài)進(jìn)行列的添加)

<el-table :data="gameareatable" v-loading="cardBuyConsumeDataLoading" v-if="gameareatable.length> 0">
 <el-table-column align="center" v-for="(item,index) in activePlayerDataPropLabelArray" :prop="item.prop" :label="item.label"
  :key="item.prop">
  <template slot-scope="scope">
  {{scope.row[item.prop]&#63;scope.row[item.prop]:'暫無數(shù)據(jù)'}}
  </template>
 </el-table-column>
 </el-table>

export default {
 data(){
  return{
  // 數(shù)據(jù)結(jié)構(gòu) activePlayerDataPropLabelArray為label標(biāo)簽顯示label表示當(dāng)前列th的顯示的值,prop表示當(dāng)前'日期'列下顯示date數(shù)據(jù),'斗地主'列下顯示prop為12的數(shù)據(jù),'麻將'列下顯示prop為15的數(shù)據(jù),
   activePlayerDataPropLabelArray:[{
    label:'日期',
    prop:'date'
   },{
    label:"斗地主",
    prop:"12"
   },{
    label:'麻將',
    prop:'15'
   }],
   gameareatable:[{
    date:"2018-09-10",
    12:'老k',
    15:'一萬(wàn)'
   },{
    date:"2018-08-01",
    12:'炸彈',
    15:'一條' 
   },{
    date:"2018-08-02",
    12:'對(duì)子',
    15:'五筒' 
   }]
  }
 }
}
日期斗地主麻將
2018-09-10老k一萬(wàn)
2018-08-01炸彈一條
2018-08-02對(duì)子一萬(wàn)

以上就是利用vue如何實(shí)現(xiàn)一個(gè)動(dòng)態(tài)表格提交參數(shù)的功能,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI