简体   繁体   English

在 v-model 更改它时使用 static 值

[英]Use static value while v-model is changing it

I need to show 'product.upc' in label tag without change (static, the same value always) while v-model is changing the value by input.我需要在 label 标签中显示“product.upc”而不更改(静态,始终相同的值),而 v-model 通过输入更改值。

    <div class="input-group-prepend">
        <label class="input-group-text p-0">@{{ product.upc }}</label>
   </div>
   <input type="text" class="form-control text-center" v-model="product.upc">

v-model is a two-way binding that will surely update wherever it is being used, so use another variable for your label instead. v-model是一种双向绑定,它肯定会在任何使用它的地方更新,因此请为您的 label 使用另一个变量。

For example, on the mounted hook, you can set the initial value of product.upc in another data variable and use that as your label.例如,在挂载的挂钩上,您可以在另一个数据变量中设置product.upc的初始值,并将其用作您的 label。

On Js side-

data() {
  return {
    label: null,
    product: {
      upc: "something",
    }
  }
},
mounted() {
  this.label = product.upc
}

On the template side-

<div class="input-group-prepend">
  <label class="input-group-text p-0">@{{ label }}</label>
</div>
<input type="text" class="form-control text-center" v-model="product.upc">

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

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