"RouteRecordRaw" is a type that must be imported using type-only imports when both "preserveValueImports" and "isolatedModules" are enabled.

When developing with vue3+ts, when configuring routing, the following problems occur:

 When declaring routes by referring to RouteRecordRaw, an error is reported.

Solution:

the first method:

When importing, it is introduced in the form of type, and type is added in front:

import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

The second method:

Find the tsconfig.json file in the root directory , set preserveValueImports: false

"compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },


"preserveValueImports": false

The above problem can be solved like this.

Guess you like

Origin blog.csdn.net/weixin_52020362/article/details/127934366