1. The difference between v-model and v-bind
v-bind
Yes单向绑定
, it is used to bind data and attributes and expressions, and can onlyvue
synchronize the data in the page to the page.v-model
Yes双向绑定
, not only canvue
the data in be synchronized to the page, but also the data of user data can be assigned tovue
the properties in.v-bind
It can be given任何属性赋值
;v-model
it can only be given tovalue属性
the elements that have it数据双向绑定
.
Two, v-model
v-model is mostly used in forms, creating two-way bindings on form elements, selecting the correct method to update elements according to the control type, and bindingtext、radio、checkbox、selected
Three, v-bind
- Binding text: use directly
v-bind
or{ {}}
<p v-bind="mgs"></p> <p>{ { mgs }}</p>
- bind property
<img v-bind:src="'//www.baidu.com/img/flexible/logo/pc/result.png'" /> <div v-bind:class="'className'">class</div> <div v-bind:style="{color: 'red'}">class</div> <p>---------------------------------------------</p> <img :src="'//www.baidu.com/img/flexible/logo/pc/result.png'" /> <div :class="'className'">class</div> <div :style="{color: 'red'}">class</div>
- binding expression
{ { number + 1 }} { { isTrue ? 'a' : 'b' }} { { msg.split('').reverse().join('') }}
- Binding
html
: Three must be used at this time{}
{ { {'<div style="color: red;">test</div>'}}}
v-bind
Multiple properties can be bound at the same time<CT v-bind="bindmodal"></CT> <CT v-bind:a="bindmodal.a"></CT> <CT :a="bindmodal.a" :b="bindmodal.b"></CT>