Vue.js + Element UI:获取“event.target";在变化 [英] Vue.js + Element UI: Get "event.target" at change

查看:49
本文介绍了Vue.js + Element UI:获取“event.target";在变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在其事件处理程序中获取触发事件的 html 字段(在 javascript 中是 event.target).

我有一个表格:

  • 附加到更改事件函数的输入元素
  • 管理更改事件的函数

我的代码如下:

var Main = {方法: {改变(标准){console.log("值为:" + par);//这里我无法得到event.target"}}};var Ctor = Vue.extend(Main)newctor().$mount('#app')

<script src="//unpkg.com/vue/dist/vue.js"></script><script src="//unpkg.com/element-ui@1.4.0-beta.1/lib/index.js"></script><div id="应用程序"><模板><el-input @change="change" placeholder="在这里输入内容"/></模板>

我知道我可以调用不同的函数,并且在每个函数中我都知道谁是相对输入,但我想使用一个通用函数.

按照我在 element-ui.common.js 中看到的堆栈跟踪,事件触发的代码:

handleChange: function handleChange(event) {this.$emit('change', event.target.value);},

然后 element 只将值传递给事件处理程序.
无论如何,有什么想法可以获取 event.target 吗?

谢谢

解决方案

可以使用@input.native

var Main = {方法: {改变(事件){console.log("值为:" + event.target.value);//这里我无法得到event.target"}}};var Ctor = Vue.extend(Main)newctor().$mount('#app')

<script src="//unpkg.com/vue/dist/vue.js"></script><script src="//unpkg.com/element-ui@1.4.0-beta.1/lib/index.js"></script><div id="应用程序"><模板><el-input @input.native="change" placeholder="在这里输入内容"/></模板>

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.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@1.4.0-beta.1/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 common one.

Following the stacktrace I saw in element-ui.common.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

解决方案

You 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.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@1.4.0-beta.1/lib/index.js"></script>
<div id="app">
  <template>
    <el-input @input.native="change" placeholder="Input something here"/>
  </template>
</div>

这篇关于Vue.js + Element UI:获取“event.target";在变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆