2016-03-15 25 views
-1

這是對象的樣子:如何訪問下列JavaScript對象的「ondrag」方法?

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事件的正確方法?

+0

你們是不是要一個'drag'事件處理程序綁定到vue組件元素? – nils

+2

你嘗試過'this.el.ondrag'嗎? – mrahhal

+0

...因爲el是財產,而不是函數。你分配peroperties,你調用函數。 'thie.el.ondrag = function(){/ * codes here * /};'可能是要走的路。 – 2016-03-15 15:40:34

回答

1

This.el返回從Event arget繼承的DOM Element object

所以,你可以使用addEventListener()

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

,或者如 「你媽媽」 的意見建議,爲它分配:

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