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

前端 未结 5 800
小蘑菇
小蘑菇 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:48

    v-model is for two way bindings means: if you change input value, the bound data will be changed and vice versa. But v-bind:value is called one way binding that means: you can change input value by changing bound data but you can't change bound data by changing input value through the element.

    v-model is intended to be used with form elements. It allows you to tie the form element (e.g. a text input) with the data object in your Vue instance.

    Example: https://jsfiddle.net/jamesbrndwgn/j2yb9zt1/1/

    v-bind is intended to be used with components to create custom props. This allows you to pass data to a component. As the prop is reactive, if the data that’s passed to the component changes then the component will reflect this change

    Example: https://jsfiddle.net/jamesbrndwgn/ws5kad1c/3/
    

    Hope this helps you with basic understanding.

提交回复
热议问题