javascript - 如何访问以下JavaScript对象的 "ondrag"方法?

标签 javascript vue.js

该对象如下所示:

enter image description here

enter image description here

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

如何调用该对象的 ondrag 事件?

我尝试过这个:

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

但是我得到了:

caught TypeError: this.el is not a function

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

最佳答案

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

所以你可以使用addEventListener() :

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

或者,按照评论中的“mrahhal”建议,分配它:

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

关于javascript - 如何访问以下JavaScript对象的 "ondrag"方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36015570/

相关文章:

vue.js - 错误TypeError : Cannot read property 'match' of undefined

javascript - Cookie 的有效期不会改变。

javascript - 如果函数返回相同的输出

javascript - Google Graph DataTable + 饼图样式

vue.js - VUEJS 从列表中删除元素?

javascript - VueJs 指令双向绑定(bind)

javascript - 在表 D3 中的导入数据中放置链接

javascript - 如何将键盘按钮 "Return"更改为 "Search"以在 UIWebView 中输入?

vue.js - Multiselect 仅呈现前两项

javascript - 在 v-for 循环的某个索引上添加一个空 div