vue:this.nextTick()的使用

<template>
    <button ref="tar" type="button" name="button" @click="testClick">{{ content }}</button>
</template>
export default {
    data(){
        return {
            content: '初始值'
        }
    },
methods: {
           testClick(){
	              this.content = '改变了的值';
	              // dom元素还未更新
	              console.log(that.$refs.tar.innerText);//初始值
			this.$nextTick(() => {
	                  // dom元素更新后执行
	                  console.log(that.$refs.tar.innerText); //改变后的值
              })
        }
}

猜你喜欢

转载自blog.csdn.net/weixin_41143662/article/details/84303002