Property 'XXX' does not exist on type 'CombinedVueInstance>>'

后端 未结 4 2042
醉话见心
醉话见心 2021-01-18 04:27

I created a vue component with TypeScript, and I\'m getting this error in data() and in methods():

Property \'xxx\' does not exist          


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 04:57

    As mentioned in the Typescript Support section of the Vue documentation:

    Because of the circular nature of Vue’s declaration files, TypeScript may have difficulties inferring the types of certain methods. For this reason, you may need to annotate the return type on methods like render and those in computed.

    In your case, you should change profilePath: function () { to profilePath: function (): string {

    You might come across the same error if you have a render() method that returns a value, without a : VNode annotation.

提交回复
热议问题