首先我的项目是一个面向医院的系统
我是在三个文件里都配置了网址
第一个文件:vue.config.js
const path = require('path')
const webpack = require('webpack')
const createThemeColorReplacerPlugin = require('./config/plugin.config')
function resolve (dir) {
return path.join(__dirname, dir)
}
const vueConfig = {
publicPath: '/dist',
configureWebpack: {
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
],
externals: {}
},
chainWebpack: (config) => {
config.resolve.alias
.set('@$', resolve('src'))
const svgRule = config.module.rule('svg')
svgRule.uses.clear()
svgRule
.oneOf('inline')
.resourceQuery(/inline/)
.use('vue-svg-icon-loader')
.loader('vue-svg-icon-loader')
.end()
.end()
.oneOf('external')
.use('file-loader')
.loader('file-loader')
.options({
name: 'assets/[name].[hash:8].[ext]'
})
},
css: {
loaderOptions: {
less: {
javascriptEnabled: true
}
}
},
devServer: {
port: 8000,
proxy: {
'/admin': {
// target: 'http://压缩的网址:端口号',
target: 'http://正常调试的网址:端口号',
ws: false,
changeOrigin: true
}
}
},
productionSourceMap: false,
transpileDependencies: [],
runtimeCompiler: true
}
if (process.env.VUE_APP_PREVIEW === 'true') {
console.log('VUE_APP_PREVIEW', true)
vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
}
module.exports = vueConfig
这个文件里最重要的代码是
devServer: {
port: 8000,
proxy: {
'/admin': {
// target: 'http://压缩网址:端口号',
target: 'http://正常网址:端口号',
ws: false,
changeOrigin: true
}
}
},
第二个出现的地方 是根据自己需要 因为我用到了视频通话 需要建立连接
// 建立socket及rtc
onsocket () {
if ('WebSocket' in window) {
const onlyKey = moment().valueOf() + '_pc'
// 生产环境
// const url = window.location.hostname + ':8080' + '/websocket?Bedno=' + onlyKey
// this.ws = new WebSocket('ws://' + url)
// 开发环境
this.ws = new WebSocket('ws://网址:端口号/websocket?Bedno=' + onlyKey)
this.socket.setWs(this.ws)
} else {
this.$message.info('您的浏览器不支持websocket')
}
this.ws.onmessage = this.onmessage
this.ws.onopen = this.onopen
this.ws.onerror = this.onerror
this.ws.onclose = this.onclose
},
所以小伙伴在实际运用中,需要用到视频通话,记得需要建立socket!!
第三个出现的地方是 需要用到文件上传 所以在mounted里也需要加上
mounted () {
// 生产环境
// this.originUrl = window.location.protocol + '//' + window.location.host + '/files/'
// 开发环境=
this.originUrl = 'http://网址:端口号/files/'
this.getfilelist()
}
友情提示:小伙伴根据自己的实际需要,去增加、删除网址出现的地方!!!