当我们在开发的时候,有时候后端要去访问我们的页面,若要直接输入ip地址+端口去访问是访问不到的,那么我们前端需要做一些操作
方法1.修改config文件夹下的index.js文件
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
}
}
需要修改的地方:
host: '192.000.0.00', // can be overwritten by process.env.HOST(你电脑的ip地址)
port: 7777, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined(你想修改的端口号)
方法2.部署到nginx
a.npm run build之后在dist文件夹下打出包 static文件夹和index.html文件
b.修改conf文件下的nginx.conf文件
server {
listen 80;(重点========你要修改的端口)
server_name localhost;(也可以修改++若部署在你的电脑上别人访问,则修改为你的ip地址++自己访问就无所谓了)
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:\AAA\dist;(你的dist文件所在的位置)
index index.html index.htm;
}
c.重启.exe就可以执行
d.访问时输入localhost(或你修改过的ip地址)+你修改后的端口