vue.config.js文件得配置

const express = require('express')
const webpack = require('webpack')
const app = express()
var appData = require('./public/region.json')
var apiRoutes = express.Router();
app.use('/api', apiRoutes)
module.exports = {
	publicPath: './',
	productionSourceMap: false,
	devServer: {
		before(app) {
			app.get('/api/region', (req, res) => {
				res.json({
					data: appData
				})
			})
		},
		proxy: {
			'/test': {
				target: "http://192.168.1.xxx",
				changeOrigin: true,
				pathRewrite: {
					'/test': '/scm'
				}
			},
			
			
		},
	},

}

静态资源得位置如图所示

静态资源位置

 if (process.env.NODE_ENV === 'development') {//需要注意在开发环境和正式环境 请求得url地址的区别
				this.$axios.get('api/region').then((res) => {
					this.options = res.data.data //这个就是json文件里面得json数据
				}, function(err) {
					console.log(err)
				})
			} else {
				this.$axios.get('/region.json').then((res) => {
					this.options = res.data 
				}, function(err) {
					console.log(err)
				})
			}
Logo

前往低代码交流专区

更多推荐