官方案例如下:

<div id='example-3'>
  <input type="checkbox" id="jack" value="Jack" v-model="checkedNames">
  <label for="jack">Jack</label>
  <input type="checkbox" id="john" value="John" v-model="checkedNames">
  <label for="john">John</label>
  <input type="checkbox" id="mike" value="Mike" v-model="checkedNames">
  <label for="mike">Mike</label>
  <br>
  <span>Checked names: {{ checkedNames }}</span>
</div>
new Vue({
  el: '#example-3',
  data: {
    checkedNames: []
  }
})

 

对v-model的解释如下:

v-model 会忽略所有表单元素的 valuecheckedselected attribute 的初始值而总是将 Vue 实例的数据作为数据来源。你应该通过 JavaScript 在组件的 data 选项中声明初始值。

 

需求:value 取值改为 Vue对象中的值,而非静态值

 

方案: v-bind:value="getValue" ,即可。

v-bind官方解释:

Attribute

Mustache 语法不能作用在 HTML attribute 上,遇到这种情况应该使用 v-bind 指令

意思就是v-bind用于绑定属性值,形式如下:

v-bind:attribute     简写形式   :attribute

 

结语:用到知识,才能对知识有更好的体会。 axios 对象中需要用 that 代替 this关键值的值,因为this 在对象中有默认特殊语义,那就是指向当前对象(axios对象中使用,当然是指向axios),所以,需要通过没有特殊语义的that来更改vue对象中的值。

 

相关文章:

  • 2018-12-18
  • 2022-12-23
  • 2021-11-14
  • 2021-03-31
  • 2022-01-17
  • 2022-01-19
猜你喜欢
  • 2021-06-11
  • 2021-09-27
  • 2021-07-29
  • 2022-02-10
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案