[英]vuejs v-model let it change from one place only
hi i have vuejs2 code with laravel blade .. now my problem is that i have this vuejs2 code嗨,我有 laravel 刀片的 vuejs2 代码.. 现在我的问题是我有这个 vuejs2 代码
new Vue({
el:'.add_item_to_price_menu',
data:{
percentage:null,
},
methods:{
searchData:function(){
console.log(this.percentage);
}
}
});
and this is my blade code这是我的刀片代码
<input type='text' @keyup='searchData' v-model='percentage' id='percentage' placeholder='{{trans("language.percentage")}}' class='form-control parent' />
<input v-model='percentage' type='text' class='form-control child' />
<input v-model='percentage' type='text' class='form-control child' />
now what i want is change the parent class change the values on every child and this is working with me but when i change in child i dont want it change in every anther model percentage is there any way to do that thanks现在我想要的是改变父类改变每个孩子的价值观,这对我有用,但是当我改变孩子时,我不希望它改变每个花药模型的百分比有没有办法做到这一点谢谢
A simple way would be not to use v-model
, just :value=percentage
.一个简单的方法是不使用
v-model
,只使用:value=percentage
。
v-model
is syntactic sugar to using a prop and an event. v-model
是使用道具和事件的语法糖。 From Vue docs :来自Vue 文档:
the [...] component must:
[...] 组件必须:
- Bind the
value
attribute to avalue
prop将
value
属性绑定到value
prop- On input, emit its own custom
input
event with the new value在输入时,使用新值发出自己的自定义
input
事件
So if you only use :value
then it's a one way binding.所以如果你只使用
:value
那么它是一种单向绑定。 Just take into account that if the user changes one of those inputs, it won't be reflected in your model.请注意,如果用户更改其中一个输入,它不会反映在您的模型中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.