简体   繁体   English

vuejs输入未显示值

[英]vuejs input not showing value

Input binding issue输入绑定问题

:value not showing the value no syntax error but when I use {{ row.item.FEE }} somewhere else then it works fine.Why it is not showing value in input filed. :value 没有显示值没有语法错误但是当我在其他地方使用 {{ row.item.FEE }} 时它工作正常。为什么它没有在输入字段中显示值。 Please help.请帮忙。

    <b-form-input
      :value="row.item.FEE"
      v-model="model.Fee[row.item.id]"
      @change="changeField('FEE', model.Fee, row.item.id)"
    ></b-form-input>

I have made some modification to make thing works.我做了一些修改以使事情正常进行。

Here is my updated code这是我更新的代码

<b-form-input :value="row.item.MIN" @change="changeField('MIN', $event, row.item.id)"></b-form-input>

Removed v-model so I can see the value in input field.删除了 v-model 以便我可以看到输入字段中的值。 Used $event to get updated value on @Change Event.使用 $event 获取 @Change Event 的更新值。

I hope it helps.我希望它有所帮助。

See: https://v2.vuejs.org/v2/guide/forms.html见: https ://v2.vuejs.org/v2/guide/forms.html

v-model will ignore the initial value, checked or selected attributes found on any form elements. v-model 将忽略在任何表单元素上找到的初始值、选中或选定属性。 It will always treat the Vue instance data as the source of truth.它将始终将 Vue 实例数据视为事实来源。 You should declare the initial value on the JavaScript side, inside the data option of your component.您应该在组件的 data 选项内声明 JavaScript 端的初始值。

Try passing it to the function instead.尝试将其传递给函数。 Moreover, I do think you should use a method for v-model此外,我确实认为您应该使用 v-model 的方法

methods.modelFee = function(id){
    return this.model.Fee[id]
}
    <b-form-input
      v-model="modelFee(row.item.id)"
      @change="changeField('FEE', model.Fee, row.item.id,row.item.FEE)"
    ></b-form-input>

There are :value and v-model , but :value will be ignored and not needed.:valuev-model ,但:value将被忽略且不需要。

To initialize the value of b-form-input , you can set v-model value mode.Fee[row.item.id] as your expected value row.item.FEE when the component is mounted.要初始化b-form-input的值,您可以在安装组件时将 v-model 值mode.Fee[row.item.id]设置为期望值row.item.FEE

  <b-form-input
      v-model="model.Fee[row.item.id]"
      @change="changeField('FEE', model.Fee, row.item.id)"
    ></b-form-input>
...
  mounted() {
     this.model.Fee[this.row.item.id] = this.row.item.FEE;
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM