VueJs Conditional handlebars

Viewed 4539

I'm trying to use VueJs conditional rendering using handlebars in vueJs 2.0 as per their documentation but eslint is coming back with and error:

- avoid using JavaScript keyword as property name: "if" in expression {{#if ok}}
- avoid using JavaScript keyword as property name: "if" in expression {{/if}}

VueJs does not seem to be rendering it.

<!-- Handlebars template -->
{{#if ok}}
  <h1>Yes</h1>
{{/if}}
5 Answers

Either:

Using v-if to conditionally render

<h1 v-if="isVisible"> Yes </h1>

or using v-show to add a hidden attribute to that element style

<h1 v-show="isVisible"> Yes </h1>

either can be used but be careful with v-if since the element won't be in the DOM if the condition is not met.

Firstly, You should look at the vue documentation .https://v2.vuejs.org/v2/guide/conditional.html#v-if-vs-v-showjs and by the way, you can use "v-if" and "v-show"attributes, in flowing related to examples.

<h1 v-if='isShow'>Test</h1>
<h1 v-show='isShow'>Test</h1>
Related