Django 如何使用IP访问Vue.js应用程序
我正在使用Vue.js/Django Rest框架进行一个小项目。现在我只想访问我的作品,但我不知道我必须在浏览器中使用哪个IP地址才能看到我的作品,我尝试了一切 这是我的vue.config.js:Django 如何使用IP访问Vue.js应用程序,django,vue.js,Django,Vue.js,我正在使用Vue.js/Django Rest框架进行一个小项目。现在我只想访问我的作品,但我不知道我必须在浏览器中使用哪个IP地址才能看到我的作品,我尝试了一切 这是我的vue.config.js: const BundleTracker = require("webpack-bundle-tracker"); module.exports = { publicPath: "http://0.0.0.0:8080/", outputDi
const BundleTracker = require("webpack-bundle-tracker");
module.exports = {
publicPath: "http://0.0.0.0:8080/",
outputDir: './dist/',
chainWebpack: config => {
config
.plugin('BundleTracker')
.use(BundleTracker, [{filename: './webpack-stats.json'}])
config.output
.filename('bundle.js')
config.optimization
.splitChunks(false)
config.resolve.alias
.set('__STATIC__', 'static')
config.devServer
// the first 3 lines of the following code have been added to the configuration
.public('http://127.0.0.1:8080')
.host('127.0.0.1')
.port(8080)
.hotOnly(true)
.watchOptions({poll: 1000})
.https(false)
.disableHostCheck(true)
.headers({"Access-Control-Allow-Origin": ["\*"]})
},
// uncomment before executing 'npm run build'
// css: {
// extract: {
// filename: 'bundle.css',
// chunkFilename: 'bundle.css',
// },
// }
};
我确实执行了
npm run serve
和python manage.py runserver
操作,但当我尝试在浏览器中访问时,什么都不起作用。Vue CLI在您运行npm run serve
时输出应用程序的URL。打开那个网址,“我什么都试过了”,你能说得更具体一点吗?这是否意味着您在浏览器中尝试了localhost:8080
或127.0.0.1:8080
?您还尝试了什么?无法访问此网站127.0.0.1拒绝连接@OscarSchafer@OscarSchaferterminal give me:App运行于:-本地:-网络:@AliceMunin值得指出的是端口号(末端的8080)很重要。只要127.0.0.1
就会出现“拒绝连接”错误,但是127.0.0.1:8080
应该可以工作。其次,确保您在运行npm run serve
命令的同一台机器上进行尝试。