admin管理员组文章数量:1295294
I can't get the html field that fires the event in its event handler (in javascript is the event.target
).
I've a form with:
- an input element attached to a function on change event
- a function that manages the change event
My code is like the following:
var Main = {
methods: {
change(par) {
console.log("The value is: " + par);
//HERE I can't get "event.target"
}
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
<script src="//unpkg/vue/dist/vue.js"></script>
<script src="//unpkg/[email protected]/lib/index.js"></script>
<div id="app">
<template>
<el-input @change="change" placeholder="Input something here"/>
</template>
</div>
I can't get the html field that fires the event in its event handler (in javascript is the event.target
).
I've a form with:
- an input element attached to a function on change event
- a function that manages the change event
My code is like the following:
var Main = {
methods: {
change(par) {
console.log("The value is: " + par);
//HERE I can't get "event.target"
}
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
<script src="//unpkg./vue/dist/vue.js"></script>
<script src="//unpkg./[email protected]/lib/index.js"></script>
<div id="app">
<template>
<el-input @change="change" placeholder="Input something here"/>
</template>
</div>
I know I can call different functions, and in each one I know who is the relative input, but I'd like to use a mon one.
Following the stacktrace I saw in element-ui.mon.js
the code of event fire:
handleChange: function handleChange(event) {
this.$emit('change', event.target.value);
},
And there element
passes just the value to the event handler.
Anyway, any idea to get the event.target
, please?
Thanks
Share asked Dec 18, 2017 at 17:19 AlessandroAlessandro 4,4729 gold badges41 silver badges71 bronze badges2 Answers
Reset to default 4You can use @input.native
var Main = {
methods: {
change(event) {
console.log("The value is: " + event.target.value);
//HERE I can't get "event.target"
}
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
<script src="//unpkg./vue/dist/vue.js"></script>
<script src="//unpkg./[email protected]/lib/index.js"></script>
<div id="app">
<template>
<el-input @input.native="change" placeholder="Input something here"/>
</template>
</div>
It looks like Element UI just eats the event and returns only the value. What you could do instead of @change(change)
is @keyup.native(change)
and then your par
parameter will be the event rather than just the value.
本文标签: javascriptVuejsElement UI Get quoteventtargetquot at changeStack Overflow
版权声明:本文标题:javascript - Vue.js + Element UI: Get "event.target" at change - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741615851a2388521.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论