属性不会退出,没有类型“ Vue”

时间:2018-07-12 03:57:07

标签: javascript typescript vuejs2 vue-router

我正在使用Vue2 + VueRouter + Typescript,但是在RouteEnter之前设置数据时发生了一些错误。

顺便说一下,这个项目是由vue-cli 3.0生成的

@Component({
    async beforeRouteEnter(to, from, next) {
        if (!navigator.onLine) {
            next({ name: 'offline' })
            return
        }
        const location: Location | null = null
        try {
            location = await WechatMixin.getLocation()
        } catch (err) {
            // do nothing
            console.error(err)
        } finally {
            next((vm) => {
                vm.location = location // property location does not exit no type 'Vue'
            })
        }
    },
})
export default class OragnizationList extends Vue {
    public location: Location | null = null
}

解决这个问题的方法是

next((vm) => {
    Object.defineProperty(vm, 'location', {
        value: location,
    })
})

但这并不优雅。

0 个答案:

没有答案