[Vuejs]-Unable to reference data() in VUEjs Typescript

0๐Ÿ‘

โœ…

If you want TypeScript support you need to use defineComponent

import { defineComponent } from 'vue'
export default defineComponent({
...
})

I would recommend Volar instead of Vetur.

I would also recommend defining the types closer to the actual values:

data() {
  return {
    item: [] as Array<Number>,
    key: 0 as Number,
    keyy: 0 as Number,
    };
  },

Old answer

randomArray is not defined, you are probably missing const or let

const randomArray = [0,2] // <--

You are missing a } at the end

  }
} // <--
</script>

After these edits, your code should work: Live demo

Leave a comment