src目录用@代替

一、项目背景

uniapp+vue3+ts+vite+pinia+vant

二、配置

在vite.config.ts文件plugins同一层级加 resolve

export default defineConfig({
	plugins: [
		uni(),
		Components({
			resolvers: [VantResolver()]
		})
	],
	resolve: {
		alias: {
			"@": "/src"
		}
	}
});

在 tsconfig.json 文件的compilerOptions内加相关配置

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

然后重启VSCode

三、用法

<script lang="ts" setup>
	import { ref } from "vue";
	import http from "@/services/http";
<script>

你可能感兴趣的:(前端)