Pass input parameter to function

Asked

Viewed 526 times

1

I ran into a problem, to pass the value of my input to my function without using v-model.

I know it works that way

<Input @click="func" />

func(val){
   alert(val)
}

But then I can’t pass another parameter, ex: <Input @click="func(status)" />, this way it will receive only the value I passed, but I would like to be able, besides passing the value that is in the input, more parameters of my choice.

  • From the input itself, if you call it that <Input @click="func"> the function already receives the value if I pass the parameter val in the function, however if I pass any parameter in the click, I no longer have the value.

  • @DVD It worked, thanks

1 answer

1


You can send multiple parameters to the function, where $event will send the properties of the element, which you can capture with currentTarget:

var campo = new Vue({
  el: '#teste',
  methods: {
     func: function (a, e) {
       alert(a +"/"+ e.currentTarget.value);
     }
  }
});
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<Input value="olá!" id="teste" @click="func('status', $event)" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.