环境变量修改为VITE前缀

This commit is contained in:
灌糖包子 2026-04-28 16:49:13 +08:00
parent bcc09d7064
commit 042c1e54ed
Signed by: sookie
GPG Key ID: 67E8D0AE905C79B0
7 changed files with 11 additions and 13 deletions

4
.env
View File

@ -1,2 +1,2 @@
VUE_APP_PROXY_TARGET=https://www.colorfulsweet.site VITE_APP_PROXY_TARGET=https://www.colorfulsweet.site
VUE_APP_API_BASE=/api/v2 VITE_APP_API_BASE=/api/v2

View File

@ -4,7 +4,7 @@ import store from '@/store'
import { router } from '@/router' import { router } from '@/router'
const http = axios.create({ const http = axios.create({
baseURL: import.meta.env.VUE_APP_API_BASE, baseURL: import.meta.env.VITE_APP_API_BASE,
timeout: 10000, timeout: 10000,
paramsSerializer: { paramsSerializer: {
indexes: null indexes: null

View File

@ -210,7 +210,7 @@ class MusicPage extends Page {
} }
const store = useStore() const store = useStore()
const apiBase = import.meta.env.VUE_APP_API_BASE const apiBase = import.meta.env.VITE_APP_API_BASE
const { loading, modalLoading, total, search, setLoadData, loadDataBase, reset, pageChange, pageSizeChange } = useBaseList(new MusicPage()) const { loading, modalLoading, total, search, setLoadData, loadDataBase, reset, pageChange, pageSizeChange } = useBaseList(new MusicPage())
const currentRow = ref<MusicModel | null>(null) const currentRow = ref<MusicModel | null>(null)
const libIdSelected = ref<string | null>(null) const libIdSelected = ref<string | null>(null)

View File

@ -105,7 +105,7 @@ class PhotoWallPage extends Page {
} }
const store = useStore() const store = useStore()
const apiBase = import.meta.env.VUE_APP_API_BASE const apiBase = import.meta.env.VITE_APP_API_BASE
const { loading, total, search, setLoadData, loadDataBase, reset, pageChange, pageSizeChange } = useBaseList(new PhotoWallPage()) const { loading, total, search, setLoadData, loadDataBase, reset, pageChange, pageSizeChange } = useBaseList(new PhotoWallPage())
const allowUploadExt = ['jpg', 'jpeg', 'png'] const allowUploadExt = ['jpg', 'jpeg', 'png']

View File

@ -87,7 +87,7 @@ import { SourceImageModel } from '@/model/api/source-image'
import http from '@/utils/http' import http from '@/utils/http'
const store = useStore() const store = useStore()
const apiBase = import.meta.env.VUE_APP_API_BASE const apiBase = import.meta.env.VITE_APP_API_BASE
const { loading, total, search, setLoadData, pageChange, pageSizeChange, datetimeFormat } = useBaseList(new Page()) const { loading, total, search, setLoadData, pageChange, pageSizeChange, datetimeFormat } = useBaseList(new Page())
const allowUploadExt = ['jpg', 'jpeg', 'png', 'svg', 'ico'] const allowUploadExt = ['jpg', 'jpeg', 'png', 'svg', 'ico']

4
src/vite-env.d.ts vendored
View File

@ -1,8 +1,8 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VUE_APP_API_BASE: string readonly VITE_APP_API_BASE: string
readonly VUE_APP_PROXY_TARGET?: string readonly VITE_APP_PROXY_TARGET?: string
} }
interface ImportMeta { interface ImportMeta {

View File

@ -18,11 +18,9 @@ function resolveCommitInfo() {
export default defineConfig(({ mode }) => { export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '') const env = loadEnv(mode, process.cwd(), '')
const proxyTarget = env.VUE_APP_PROXY_TARGET || env.VITE_APP_PROXY_TARGET
return { return {
base: './', base: './',
envPrefix: ['VITE_', 'VUE_APP_'],
plugins: [ plugins: [
vue(), vue(),
AutoImport({ AutoImport({
@ -44,12 +42,12 @@ export default defineConfig(({ mode }) => {
}, },
server: { server: {
port: 8080, port: 8080,
proxy: proxyTarget ? { proxy: {
'/api': { '/api': {
target: proxyTarget, target: env.VITE_APP_PROXY_TARGET,
changeOrigin: true changeOrigin: true
} }
} : undefined }
}, },
build: { build: {
sourcemap: false, sourcemap: false,