vue子组件销毁
HTML
<template>
<!-- 需要销毁的dom -->
<div v-if="destroy"></div>
<!-- 同普通的dom,组件也是一样 -->
<component-name v-if="destroy"></component-name>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
destroy: true
}
},
methods: {
destroyDom: function() {
this.destroy = false
this.$nextTick({
this.destroy = true
})
}
}
}
</script>
销毁dom直接利用vue的v-if实现就行了,v-if为false时,dom会被移除,true时会被添加重新渲染
注意:this.nextTick(callback)会在DOM更新后回调