Vue + typescript - TypeError: Object prototype may only be an Object or null: undefined

后端 未结 6 1344
你的背包
你的背包 2020-12-19 07:48

TypeError: Object prototype may only be an Object or null: undefined

I got some error in my project. I\'m using vuejs, typescript and jest.

It\'s just simp

6条回答
  •  天涯浪人
    2020-12-19 08:34

    For me, using import * as Vue from "vue" instead of import Vue from "vue" fixed the problem for my projects with a similar setup, i.e.:

    //import Vue from "vue";
    import * as Vue from "vue";
    import Component from "vue-class-component";
    
    interface HelloWorldInterface {
      msg: string;
      clickHandler(): void;
    }
    
    @Component
    export default class HelloWorld extends Vue implements HelloWorldInterface {
      msg = "Hello!!";
      clickHandler() {
        window.alert(this.msg);
      }
    }
    

    It is a lot more cumbersome, but at least it works. I have setup a proof-of-concept example using vue-cli: https://codesandbox.io/s/mjvjw2xw39

提交回复
热议问题