When a component triggers an event, I am attempting to access one of its props. This particular component is sourced from .
Among other props like name and value, this component has several properties. My goal is to retrieve the name or value of the switch when a change event occurs.
Furthermore, how can I access any prop of the switch that initiated the change event?
I attempted the following code but received 'undefined' as a result:
<div v-for="organizer in organizers>
<el-switch @change="changeOrganizers($event.target.name, $event.target.value)" :name="organizer.name">
</el-switch>
</div>
var Main = {
data() {
return {
value1: true,
}
},
methods : {
changeSwitch(name) {
console.log(name)
}
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
http://jsfiddle.net/2hr6y79h/2/
Thank you
Solution
<div v-for="organizer in organizers>
<el-switch @change="changeOrganizers()" :name="organizer.name">
</el-switch>
</div>
var Main = {
data() {
return {
value1: true,
}
},
methods : {
changeSwitch() {
console.log(event.currentTarget.checked);
console.log(event.currentTarget.name)
}
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')