Vue.js—Difference between v-model and v-bind

前端 未结 5 805
小蘑菇
小蘑菇 2020-11-27 08:54

I\'m learning Vue with an online course and the instructor gave me an exercise to make an input text with a default value. I completed it using v-model but, the instructor c

5条回答
  •  无人及你
    2020-11-27 09:59

    From here - Remember:

    
    

    is essentially the same as:

    
    

    or (shorthand syntax):

    
    

    So v-model is a two-way binding for form inputs. It combines v-bind, which brings a js value into the markup, and v-on:input to update the js value.

    Use v-model when you can. Use v-bind/v-on when you must :-) I hope your answer was accepted.

    v-model works with all the basic HTML input types (text, textarea, number, radio, checkbox, select). You can use v-model with input type=date if your model stores dates as ISO strings (yyyy-mm-dd). If you want to use date objects in your model (a good idea as soon as you're going to manipulate or format them), do this.

    v-model has some extra smarts that it's good to be aware of. If you're using an IME ( lots of mobile keyboards, or Chinese/Japanese/Korean ), v-model will not update until a word is complete (a space is entered or the user leaves the field). v-input will fire much more frequently.

    v-model also has modifiers .lazy, .trim, .number, covered in the doc.

提交回复
热议问题