【问题标题】:How to access the "ondrag" method of the following JavaScript object?如何访问以下 JavaScript 对象的“ondrag”方法?
【发布时间】:2016-03-15 15:29:39
【问题描述】:

这是对象的样子:

这就是我访问它的方式:console.log(this)this 输出 Directive 对象)。

如何调用这个对象的ondrag事件?

我试过了:

this.el('ondrag', function(event) {
  console.log(event)
})

但我得到了:

caught TypeError: this.el is not a function

访问ondrag 事件的正确方法是什么?

【问题讨论】:

  • 您是否尝试将 drag 事件处理程序绑定到 vue 组件元素?
  • 你试过this.el.ondrag吗?
  • ... 因为 el 是属性,而不是函数。你分配属性,你调用函数。 thie.el.ondrag = function(){ /* codes here */ }; 可能是要走的路。

标签: javascript vue.js


【解决方案1】:

This.el 返回一个继承自 Event arget 的 DOM Element object

所以你可以使用addEventListener():

this.el.addEventListener('drag', function (event) {
  //....
})

或者,如 cmets 中建议的“mrahhal”,分配它:

this.el.ondrag = function(event) {
  // ...
}

【讨论】:

    猜你喜欢
    • 2019-08-28
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多