vue-switches icon indicating copy to clipboard operation
vue-switches copied to clipboard

v-on events are not working

Open dkrasov opened this issue 6 years ago • 14 comments

Hi!

I'm using your component, and I've noticed that v-on events (nor @change) are not working with your component, so I'm using watchers for my properties bound to switches.

The events support would be great improvement IMO.

dkrasov avatar Nov 19 '17 15:11 dkrasov

@dmitriymarley you should use @input is not documented but you can find it in code

b4dnewz avatar Dec 24 '17 13:12 b4dnewz

[Vue warn]: Error in event handler for "input": "ReferenceError: array is not defined"

found in

---> <Switches> at node_modules\vue-switches\src\switches.vue <Home> at src\components\home.vue <App> at src\App.vue <Root>

help? I just wanna add an event listener

DulanHewage avatar Feb 07 '18 04:02 DulanHewage

@Dulan666 ensure that your "array" property which could possibly be in data or computed actually exists.. read the error message: array is not defined

b4dnewz avatar Feb 07 '18 07:02 b4dnewz

@dkrasov Using emitters is needed because this is a component that must announce that an action is happening to other components. It's pretty easy to then "listen" to this data emitted and then perform whatever method or action you need. You can see example and setup here:

https://stackoverflow.com/questions/40300634/emit-an-event-from-child-to-parent-in-vue-js-es6-syntax

tophat1986 avatar Aug 07 '18 16:08 tophat1986

how can i sent the current status and also an identifier?

@input="setStatus(id, isOn)"

for example?

antonioreyna avatar Feb 28 '19 09:02 antonioreyna

@antonioreyna you can use the $event keyword which contains the original event or in this case the updated value (i guess)

is that what you are looking for?

b4dnewz avatar Feb 28 '19 09:02 b4dnewz

@dkrasov yes! now i get my id and the value, but then the switch does not animate to the true or false value it keeps on OFF

antonioreyna avatar Feb 28 '19 09:02 antonioreyna

this is my switch code:

switches(color="green", :value="servicio.realizado",  :emit-on-mount="false", :type-bold="true", @input="setRealizado(servicio.id, $event)")

then on my method just:

setRealizado: function(id, event) {
            console.log('id', id);
            console.log('val', event);
}

antonioreyna avatar Feb 28 '19 09:02 antonioreyna

use v-model instead of v-value, otherwise you need to update it by yourself

b4dnewz avatar Feb 28 '19 09:02 b4dnewz

the thing is that my v-model in this case is a list of dates so if the date is null then the switch is off and if it is a date the switch is on, if i set it v-model it changes my date to true or false, can you tell me how do i update it manually then in my method?

thank you so much for your help

antonioreyna avatar Feb 28 '19 09:02 antonioreyna

setRealizado: function(id, event) {
            console.log('id', id);
            console.log('val', event);
            this.servicio.realizado = event
}

this in case event is the boolean switch value, to explain it a little bit, the v-value determine the "state" of the switch same as a normal checked attribute on a checkbox html input, when you toggle it the switch component react to its changes

b4dnewz avatar Feb 28 '19 09:02 b4dnewz

got it! i had to create a new array for my switches v-model but now its working thank you so much!

antonioreyna avatar Feb 28 '19 09:02 antonioreyna

ningún problema amigo

b4dnewz avatar Feb 28 '19 09:02 b4dnewz

Hi! @change is not working during the switching please resolve this issue. Thanks

abdullah-336 avatar Mar 10 '22 14:03 abdullah-336