将输入值传递给v模型 [英] Pass value of input to v-model
问题描述
如何自动将输入值传递给v模型? 谢谢:)
how to pass automatticly the value of the input into the v-model ? Thank you :)
代码:
<input value="{{$in->id}}" v-model="upload.id" >
我试图用我的脚本来做:
i tried to do in my script :
upload: {
bank:'',
id:{{$in->id}},
cash:''
},
在我看来:
<a value="" v-model="upload.id" ></a>
推荐答案
您不能那样做,因为v-model
会覆盖输入元素上的value
属性.因此,最好的选择可能是将其直接添加到您的script
标记中.
You can't do it that way as v-model
overrides the value
attribute on the input element. So probably the best option would be to add this straight to your script
tag.
<script type="text/javascript>
new Vue({
data: {
upload {
id: {{$in->id}}
}
}
});
</script>
或者,如果要在其自己的javascript文件中启动VueJS,则可以将其设置为窗口中的属性,而不是内联.例如,在您的<head>
中,您可以执行以下操作:
Or, if you are initiating VueJS within it's own javascript file, instead of inline you could set it as a property on the window. For example, in your <head>
you can do the following:
<head>
...
<script type="text/javascript">
window.sharedData = window.sharedData || {};
window.sharedData.uploadId = {{$in->id}};
</script>
...
</head>
这意味着您可以在javascript文件中执行以下操作:
This means in your javascript file you could then do the following:
data: {
upload: {
in: window.sharedData.uploadId
}
}
这篇关于将输入值传递给v模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!