N
N
NDll2021-06-02 23:08:51
typescript
NDll, 2021-06-02 23:08:51

Why does Nuxt + TypeScript give an error?

<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
  data() {
    return {
        tag: this.$route.params.tag
    }
  },
})
</script>


why on $route issues

any
Property '$route' does not exist on type 'Readonly<Record<never, any>> & Vue'.Vetur(2339)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-06-03
@Aetae

Did you use the instruction or did you just randomly connect TypeScript to Nuxt?
The fact is that Nuxt connects a lot of things implicitly, incl. and router, so TypeScript is unaware that Vueadditional type properties have been added to the type $route. It is necessary to connect declarations separately manually, or follow the instructions above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question