yassine j
yassine j

Reputation: 515

Pass value of input to v-model

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>

Upvotes: 0

Views: 1071

Answers (1)

George Hanson
George Hanson

Reputation: 3030

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
  }
}

Upvotes: 2

Related Questions