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

后端 未结 4 2045
醉话见心
醉话见心 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 05:00

    You need to use function in the correct way to preserve the reference of this.

    methods: {
                toggle() {
                    this.open = !this.open
                    if (this.open) {
                        // Add click listener to whole page to close dropdown
                        document.addEventListener('click', this.close)
                    }
                },
                close() {
                    this.open = false;
                    document.removeEventListener('click', this.close)
                }
            }
    

提交回复
热议问题