0

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>
yassine j
  • 495
  • 1
  • 11
  • 27
  • @Badgy, it's Vue.js, as per the tags. – Adam Sep 11 '18 at 13:21
  • 1
    @Adam yes i know but i doubt there is no cleaner solution to even get the data etc. he managed to make it look like a mess with only 3 lines of code – niclas_4 Sep 11 '18 at 13:35

1 Answers1

2

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
  }
}
George Hanson
  • 2,940
  • 1
  • 6
  • 18