问答

typescript vue Throttle ResizeObserver this指向错误?

作者:admin 2021-06-07 我要评论

我在用Typescript重构vue组件时,loash的Throttle方法this的指向错误, template lang="pug" .vue-waterfall-ex-container( ref="outerEl" )/templatescript lan...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

我在用Typescript重构vue组件时,loash的Throttle方法this的指向错误,

<template lang="pug">
    .vue-waterfall-ex-container( ref="outerEl" )
</template>

<script lang="ts">
    import { Component, Vue, Prop, Watch, Ref, Emit } from "vue-property-decorator"
    import { Throttle } from "lodash-decorators"

    @Ref("outerEl") readonly outerEl: HTMLDivElement

    @Component
    export default class VueWaterfallEx extends Vue {
        private mounted(): void {
            this.resizeObserver = new ResizeObserver(this.onContainerResized)
            this.resizeObserver.observe(this.outerEl)
        }
        
        @Throttle(250)
        private onContainerResized(): void {
            console.log(this) // 打印 ResizeObserver {}, 这里的this指向错误
        }
    }
</script>

请问,这应该怎么解决呢?

###

函数都写到class外了...

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • PHP-fpm怎么实现进程间同步与互斥的?

    PHP-fpm怎么实现进程间同步与互斥的?

  • ts类型问题

    ts类型问题

  • js不带引号的对象格式字符串怎么转为对

    js不带引号的对象格式字符串怎么转为对

  • Number.prototype.toFixed() 四舍五入

    Number.prototype.toFixed() 四舍五入

腾讯云代理商
海外云服务器