在Vue中,我们可能对一个组件有很多业务引用。例如,数学有10种不同类型的tab题,但它指的是一个公共组件。这时候,当我们在tab之间切换的时候,就会报组件的name值错误,或者组件还没有重新渲染。这时候我们需要使用键值销毁组件data:function(){return{componentKey:0,};},tabClick:function(item){this.componentKey+=1;}方法二v-iftabClick:function(item){this.renderComponent=false;this.$nextTick(()=>{//在DOM中添加组件组件this.renderComponent=true;});}
Vue强制组件重新渲染相关文章