Pass value of input to v-model

余生颓废 提交于 2019-12-25 00:21:17

问题


how to pass automatticly the value of the input into the v-model ? Thank you :)

Code :

  <input   value="{{$in->id}}" v-model="upload.id" >

i tried to do in my script :

 upload: {
        bank:'',
        id:{{$in->id}},
        cash:''
  },

and in my view :

  <a   value="" v-model="upload.id" ></a>

回答1:


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>

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>

This means in your javascript file you could then do the following:

data: {
  upload: {
    in: window.sharedData.uploadId
  }
}


来源:https://stackoverflow.com/questions/52276329/pass-value-of-input-to-v-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!