$nextTick 作用

阅读数: 635 2022年03月26日

$nextTick 是在下次 DOM 更新循环结束之后执行延迟回调,在修改数据之后使用 $nextTick,则可以在回调中获取更新后的 DOM。

//获得接口数据后,在页面更新完成再赋值数据
await this.$request({
	...
}).then((res) => {
	if (res.code === 0) {
		that.$nextTick(() => {
			that.bannerList = res.data.banner_list;
			that.noticeData = res.data.notice;
			that.shareData = res.data.share;
			that.menusData = res.data.menus;
			that.statusData = res.data.status;
		});
	}
}).catch((errorMsg) => {
    ...
});


参考资料
https://zhuanlan.zhihu.com/p/26724001
https://blog.csdn.net/zhouzuoluo/article/details/84752280
phpriji.cn | 网站地图 | 沪ICP备17015433号-1