- 下载 unplugin-auto-import插件
npm install unplugin-auto-import -D
- vue.config.js修改配置
const AutoImport = require("unplugin-auto-import/webpack");
configureWebpack :{
plugins:[
AutoImport({
//自动引入vue vue-router pinia api
imports: ['vue', 'vue-router','pinia'],
eslintrc: {
//先设置成true npm run dev后会生成.eslintrc-auto-import.json 然后改成false 生成一次就行
enabled: true, // Default `false`,
//生成ts声明文件
dts: "typings/auto-imports.d.ts",
},
})
]
}
3…eslintrc.js 修改配置
extends:[
plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/typescript/recommended',
'plugin:prettier/recommended',
//增加这一行
'./.eslintrc-auto-import.json',
]