例:
<divid="app"><button@click="add">按钮</button><ulref="ul"><liv-for="(el,index) in arr":key=index>{{el}}</li></ul></div><scripttype="text/javascript">//注意:数据改变是同步操作,数据刷新获取dom树比较是异步操作,所以在获取时获取不到。const vm =newVue({
el:"#app",
data:{
arr:[1,2,3,4]},methods:{add(){//此时新增加了一条,想获取最新lithis.arr.push(this.arr.length+1);//导致新增的不是最后一个// this.$refs.ul.lastChild.style.backgroundColor="blue"//解决办法:增加后调用回调this.$nextTick(()=>{this.$refs.ul.lastChild.style.backgroundColor="blue"})}}})</script>