Vue v-if problem js dynamically create div setAttribute add v-if no response

problem description

vue v-if,jsdiv,setAttributev-if,

the environmental background of the problems and what methods you have tried

create div, dynamically through js, and then bind div to VMI if to add judgment conditions. True and false, can be seen in html but not hidden

related codes

/ / Please paste the code text below (do not replace the code with pictures)

 var newDiv =document.createElement("div")
 newDiv.setAttribute("v-if",pagedata[i]._Id===this.showPageBox)

what result do you expect? What is the error message actually seen?

is there a way to control

Dec.23,2021

content is inserted as normal HTML-not compiled as a Vue template
can be reconsidered by using components instead.


Why use js to create dom dynamically? You can just manipulate the data, or the elements in the array, and then loop and render it. I don't feel like following the idea of mvvm to develop!


the dynamic generation of js will certainly not work. It should be written in template


the core of vue is that MVVM, data drives the owner of DOM, buildings. This is not a best practice. As to why it does not take effect, it has been said on the first floor

Menu