在输入内容过程中匹配到下划线__后在表格中新增加对应的行,删除下划线后表格中对应的行删除
<template lang="pug">
textarea(v-model.lazy="str")
// 输入框自己写
</template>
<script>
export default {
data() {
return {
str: '',
};
},
computed: {
blanks() {
return this.str.match(/_{2,}/g);
}
}
}
</script>
用 lazy
是希望不要刷新太多次,影响效率。
// html
<el-input
type="textarea"
:rows="4"
placeholder="请输入内容"
v-model="textarea"
@change="textareaChange">
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
type="index"
label="序号"
width="180">
</el-table-column>
<el-table-column
prop="name"
label="名称"
width="180">
<template slot-scope="scope">
<el-input v-model="scope.row.name"></el-input>
</template>
</el-table-column>
<el-table-column
prop="age"
label="年龄">
<template slot-scope="scope">
<el-input v-model="scope.row.age"></el-input>
</template>
</el-table-column>
<el-table-column
label="操作">
<template slot-scope="scope">
<el-button type="text" @click="handleDelete(scope)">删除</el-button>
</template>
</el-table-column>
</el-table>
export default {
data: {
textarea: '',
tableData: []
},
methods: {
textareaChange(value) {
this.tableData = value.split('_').map(item => ({name: '', age: '', value: item}))
},
handleDelete(scope) {
const {$index} = scope
this.tableData.splice($index, 1)
},
}
}
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决