1 table添加ref属性
<el-table
ref="table"
:data="form.items"
height="300"
style="width: 100%">
// 滚动到第一行
this.$refs.table.bodyWrapper.scrollTop =0;
// 滚动到最后一行
this.$refs.table.bodyWrapper.scrollTop =this.$refs.table.bodyWrapper.scrollHeight;
// 添加
handleAddItem() {
// 向数组中添加一条数据
this.form.items.push({itemName: ''});
//滚动到最后一行
this.$nextTick(function(){ //此处必须使用nextTick函数,使页面渲染完后再执行
this.$refs.table.bodyWrapper.scrollTop =this.$refs.table.bodyWrapper.scrollHeight;
});
},