Vue.js if there is more

Is it possible to have an if / else statement that does not display any html in a knockout-like view:

<!-- ko if: someExpressionGoesHere --> 
+6
source share
1 answer

but it should be on the element

Yes, but if v-if conditional value is false, it is not added to the DOM tree.

HTML

 <div id="main"></div> 

Javascript

 new Vue({ el: "#main", template: '<div v-if="name"><span v-text="name"></span></div>', data: { // name: "bob" } }); console.log(document.body.innerHTML); // <div id="main"><!--vue-if--></div> 

Still not good for you?

+10
source

Source: https://habr.com/ru/post/971823/


All Articles