When is the function being calculated called?

Asked 2 years ago, Updated 2 years ago, 71 views

I don't know the flow of treatment.
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>
  <p>
    <input type="text" v-on:input="updateName($event)">
  </p>
  <pv-show="!isValid">
    Please enter a name
  </p>
  <pv-show="isValid">
    <button v-on:click="sendData">Send</button>
  </p>
</div>

and

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

and so on.Anything you don't understand is

com When is the computed called?

updateName:function(event){
    this.name=event.target.value;
}

Why is this from this.name? Where does event.target.value refer to?
That's it.

I have no idea about に, but is it when v-bind:style="{'border':(isValid?':'1px solid red')}" is called?

html vue.js

2022-09-30 19:43

1 Answers

< When is the isValid function called instead of computed?I think it means that
Invoked roughly when the Vue object is initialized and when the name value changes.

<this is required because updateName is called so that Vue.js is this===vm.
event.target.value is the value entered in the input element.

If you are studying Vue.js, it would be more efficient and accurate to read official documents instead of old information.

For example, for re, Calculation properties and watcher—Vue.js have almost all the answers.


2022-09-30 19:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.