[Vuejs]-Vue string matching in handlebars {{myString !== "" ? myString : otherString}}

0๐Ÿ‘

โœ…

if(value) was the answer here, to cover all the conditions I needed

so {{ myString ? ... : ... }}

๐Ÿ‘คCQM

0๐Ÿ‘

The ternary operator works fine on the template.
Check your myString data it might not be empty.

  <div>Empty: {{myString === "" ? 'test' : otherString}}<div>
  <div>Non Empty: {{myString !== "" ? 'test' : otherString}}<div>

See the example below.

var app = new Vue({
  el: '#app',
  data() {
    return {
     myString: "",
     otherString: "blah"
    }
   },
})
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<div id="app">
  <div>Empty: {{myString === "" ? 'test' : otherString}}<div>
  <div>Non Empty: {{myString !== "" ? 'test' : otherString}}<div>
  
</div>
๐Ÿ‘คcalmar

Leave a comment