Vue + typescript:Property 'xxx' does not exist on type' Vue'.

< H2 > question: vue + typescript practice. Vscode prompts for properties and methods that are not defined under the vue object (in fact, they have already been defined) < / H2 >
related codes and hints:
export default Vue.extend({
  props: {
    menu: {
      type: Array,
      default: () => []
    }
  },
  name: "navHeaderMenu",
  data() {
    return {
      hoverIndex: ""
    }
  },
  methods: {
    triggerToMousemove(i: number): void {
      // :
      // vscode :Property "hoverIndex" does not exist on type "Vue".
      this.houverIndex = i
      // vscode :Property "test" does not exist no type "Vue".
      this.ab()
      // :
      // vscode 
      (this as any).houverIndex = i
      (this as any).test()
      this.$emit("mouseover", i)
    },
    triggerToMouseout(i: number): void {
      (this as any).hoverIndex = ""
      this.$emit("mouseout", i)
    },
    test() {
        console.log("test")
    },
  },
})
< H2 > questions < / H2 >
  • Why does vscode prompt: Property xxx does not exist on type "Vue"
  • after Baidu, using this syntax of typescript, (this as any). Xxx will not prompt for error messages. Do not understand the meaning of the grammatical expression of (this as any). Xxx, can you give us some advice? thank you.
  • besides (this as any). Xxx syntax, is there any other way to solve similar problems in error reporting

use Vue.extend or vue-class-component
refer to the official website ide/typescript.html-sharpad" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.

Menu