el-form嵌套el-tab再嵌套el-form

el-form嵌套el-tab再嵌套el-form

为啥加了这个div就ok了

<template>

<el-container>

<el-form ref="form" :model="form" label-width="80px" :rules="rules">

<el-form-item label="活动名称" prop="name">

<el-input v-model="form.name"></el-input>

</el-form-item>

<el-tabs v-model="editableTabsValue" type="card" editable @edit="handleTabsEdit">

<el-tab-pane :key="item.name" v-for="item in form.tableForms" :label="item.title" :name="item.name">

<!-- amazing div -->

<div>

<el-form :model="item" ref="tableForm" :rules="tableFormRule">

<el-form-item label="tableName" prop="tableName">

<el-input v-model="item.tableName"></el-input>

</el-form-item>

</el-form>

</div>

</el-tab-pane>

</el-tabs>

<el-form-item>

<el-button type="primary" @click="submitForm('form')">立即创建</el-button>

<el-button>取消</el-button>

</el-form-item>

</el-form>

</el-container>

</template>

<script>

export default {

name: 'HelloWorld',

data() {

return {

id: 1,

tableFormRule: {

tableName: [

{required: true, message: '请输入活动名称', trigger: 'blur'},

{min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}

],

},

rules: {

name: [

{required: true, message: '请输入活动名称', trigger: 'blur'},

{min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}

]

},

form: {

name: '',

region: '',

date1: '',

date2: '',

delivery: false,

type: [],

resource: '',

desc: '',

tableForms: [{

id: 1,

title: '11',

name: '1',

tableName: ''

}]

},

editableTabsValue: '1',

tabIndex: 2

}

},

methods: {

submitForm(formName) {

this.$refs[formName].validate((valid) => {

if (valid) {

for (let i = 0; i < this.$refs["tableForm"].length; i++) {

this.$refs["tableForm"][i].validate(isVaild => {

if (isVaild) {

console.log("ffff");

} else {

console.log("1111");

}

});

}

} else {

console.log('error submit!!');

return false;

}

});

},

handleTabsEdit(targetName, action) {

if (action === 'add') {

let newTabName = ++this.tabIndex + '';

this.id++;

this.form.tableForms.push({

id: this.id,

title: 'New Tab',

name: newTabName,

content: 'New Tab content'

});

this.editableTabsValue = newTabName;

}

if (action === 'remove') {

let tabs = this.form.tableForms;

let activeName = this.editableTabsValue;

if (activeName === targetName) {

tabs.forEach((tab, index) => {

if (tab.name === targetName) {

let nextTab = tabs[index + 1] || tabs[index - 1];

if (nextTab) {

activeName = nextTab.name;

}

}

});

}

this.editableTabsValue = activeName;

this.form.tableForms = tabs.filter(tab => tab.name !== targetName);

}

}

}

}

</script>

以上是 el-form嵌套el-tab再嵌套el-form 的全部内容, 来源链接: utcz.com/p/936702.html

回到顶部