vue之$nextTick(callback)作用
- this.$nextTick(callback) 作用:处理vue中的dom异步更新,粗暴的说就是dom渲染之后,就会执行callback函数
<template>
<div>
<div ref="msgRef">about1 {{ msg }}</div>
<button @click="btn">修改msg</button>
</div>
</template>
<script>
export default {
name: "About1",
components: {},
data() {
return {
msg: "我是msg啊",
};
},
methods: {
btn() {
this.msg = "我是修改后的msg";
console.log("msg", this.msg);
console.log("msgRef", this.$refs.msgRef.innerHTML);
this.$nextTick(() => {
console.log("nextTick", this.$refs.msgRef.innerHTML);
})
},
},
};
</script>
vue之$nextTick(callback)源码
|