I don't understand the meaning of isValid? and "!isValid"

Asked 2 years ago, Updated 2 years ago, 92 views

I am studying Vue.js by referring to http://gihyo.jp/dev/serial/01/vuejs/0002?page=2.

in html
<divid="example" v-bind:style="{'border':(isValid?':'1px solid red')}">
  <p>Name {{name}}</p>
  <pv-show="!isValid">
    Please enter a name
  </p>
</div>

and to js

 varvm = new Vue({
  el: '#example',
  data: {
    name: '' ,
  },
  computed: {
    isValid: function() {
      return this.name.length>0;
    }
  }
});
window.vm=vm;

"However, I do not understand the meaning of this isValid? and ""!isValid""When I move these codes, the red box and the letter "Please enter your name" are always displayed, but I thought isValid? and !isValid would be a match, but I didn't understand that these two were always displayed.

html vue.js

2022-09-30 10:49

1 Answers

isValid?'': '1px solid red' returns ' if isValid is true and false returns '1px solid red'.
In other words, if isValid==false, a red frame is displayed.
!isValid is the reversal of true and false, so isValid==false displays 名前Please enter a name を.


2022-09-30 10:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.