admin管理员组文章数量:1327988
i need to remove the event listener. i'm calling to some method from the function executed within the event listener, so i need to use to es6 syntax. i couldn't use named functions. how can i remove the event listener
methods :
initCanvas : function(x, y, width, height) {
//do something
},
some_method : function() {
let svgObjectEl = // some logic will give the object elemenet embedding the svg
svgObjectEl.addEventListener('load', () => {
//let x,y,width, height has some value
// some code here
this.initCanvas(x, y, width, height);
});
svgObjectEl.removeEventListener('load', ??);
}
i need to remove the event listener. i'm calling to some method from the function executed within the event listener, so i need to use to es6 syntax. i couldn't use named functions. how can i remove the event listener
methods :
initCanvas : function(x, y, width, height) {
//do something
},
some_method : function() {
let svgObjectEl = // some logic will give the object elemenet embedding the svg
svgObjectEl.addEventListener('load', () => {
//let x,y,width, height has some value
// some code here
this.initCanvas(x, y, width, height);
});
svgObjectEl.removeEventListener('load', ??);
}
Share
Improve this question
edited Dec 5, 2017 at 17:38
Tomonso Ejang
asked Dec 1, 2017 at 17:55
Tomonso EjangTomonso Ejang
1,3664 gold badges16 silver badges28 bronze badges
4
- 2 You need to store it in a variable. – SLaks Commented Dec 1, 2017 at 17:57
- can you write it out. – Tomonso Ejang Commented Dec 1, 2017 at 18:11
-
1
wouldn't
<svg @load.once="listener" ...
do it ? – birdspider Commented Dec 1, 2017 at 18:29 - @birdspider No. i had to perform some logic – Tomonso Ejang Commented Dec 1, 2017 at 18:52
1 Answer
Reset to default 2Something like this maybe?
methods: {
initCanvas (x, y, width, height) {
//do something
},
some_method() {
svgObjectEl.options = { x: 12, y: 13, … }
svgObjectEl.addEventListener('load', this.listener)
},
listener(evt) {
// some code here
this.initCanvas(evt.target.options)
svgObjectEl.removeEventListener('load', this.listener)
}
}
本文标签: javascriptremove event listener in vueStack Overflow
版权声明:本文标题:javascript - remove event listener in vue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742250349a2440639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论