vue+typescript无法使用this.$options.data()

export default class Test extends Vue {
    
    t = "测试"

    created() {
            console.log(this.$options.data())
            //Error in created hook: "TypeError: Cannot read property 'props' of undefined"
            console.log(this.$options.data.call(this))
            //{}   call的话 返回的是空对象,没有t
        }
 }   
    

放到普通的js版的vue 就没问题~~ 求大佬们帮助~万分感谢~

阅读 4.8k
2 个回答

重置的话使用

Object.assign(this.$data, this.$options.data.call(this))
Object.assign(this.$data.target, this.$options.data.call(this).target)

vue-class-component对data做了包裹,导致this.$options.data没有返回我们想要的值

推荐问题