我在用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外了...