el-table 点击按钮 表格自动增加一行,同时新增的行input 自动获取焦点
1 vue
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@2.15.5/lib/index.js"></script>
<div id="app">
<el-button type="primary" @click="btnclick">主要按钮</el-button>
<el-input id="aaa" ref="aa" v-model="input" placeholder="请输入内容">
</el-input>
<el-table :data="tabledata">
<el-table-column label='id' prop='id'></el-table-column>
<el-table-column label="名字" prop='name'>
<template slot-scope="scope">
<input :id="'name'+scope.row.id" type='text' v-model='scope.row.name' />
</template>
</el-table-column>
</el-table>
</el-table>
</div>
2 js
var Main = {
data() {
return {
input: '',
tabledata:[]
}
},
methods:{
btnclick(){
console.log('aa');
this.input = "aaa";
this.tabledata.push({id:1,name:'sj'});
var that = this;
this.$nextTick(function () {
document.getElementById('name1').focus();
})
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
本作品采用《CC 协议》,转载必须注明作者和本文链接