Vue v-bind与v-model的区别

v-bind    缩写 : 

动态地绑定一个或多个特性,或一个组件 prop 到表达式。

官网举例

  1.  
    <!-- 绑定一个属性 -->
  2.  
    <img v-bind:src="imageSrc">
  3.  
     
  4.  
    <!-- 缩写 -->
  5.  
    <img :src="imageSrc">
  6.  
     
  7.  
    <!-- 内联字符串拼接 -->
  8.  
    <img :src="'/path/to/images/' + fileName">
  9.  
     
  10.  
    <!-- class 绑定 -->
  11.  
    <div :class="{ red: isRed }"></div>
  12.  
    <div :class="[classA, classB]"></div>
  13.  
    <div :class="[classA, { classB: isB, classC: isC }]">
  14.  
     
  15.  
    <!-- style 绑定 -->
  16.  
    <div :style="{ fontSize: size + 'px' }"></div>
  17.  
    <div :style="[styleObjectA, styleObjectB]"></div>
  18.  
     
  19.  
    <!-- 绑定一个有属性的对象 -->
  20.  
    <div v-bind="{ id: someProp, 'other-attr': otherProp }"></div>
  21.  
     
  22.  
    <!-- 通过 prop 修饰符绑定 DOM 属性 -->
  23.  
    <div v-bind:text-content.prop="text"></div>
  24.  
     
  25.  
    <!-- prop 绑定。“prop”必须在 my-component 中声明。-->
  26.  
    <my-component :prop="someThing"></my-component>
  27.  
     
  28.  
    <!-- 通过 $props 将父组件的 props 一起传给子组件 -->
  29.  
    <child-component v-bind="$props"></child-component>
  30.  
     
  31.  
    <!-- XLink -->
  32.  
    <svg><a :xlink:special="foo"></a></svg>



v-model

在表单控件或者组件上创建双向绑定。

举例

  1.  
    <input v-model="message" placeholder="edit me">
  2.  
    <p>Message is: {{ message }}</p>


message 会根据输入变化

 

原文地址:https://www.cnblogs.com/qqhfeng/p/11483581.html