vue把localhost改成ip地址無法訪問—解決方法

開發Vue spa 商城進行真機測試的時候,原本在/config下的index.js/host

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

module.exports = {
  dev: {
    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    // Various Dev Server settings
    // host: 'localhost'
    host: '192.168.xx.xx', // 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-

    proxyTable: {
      '/api': {
        target: 'xxxxxxxxxx',
        secure: false,
        changeOrigin: true,
        pathRewrite: {'^/api': ''}
      }
    },


    /**
     * Source Maps
     */
    devtool: 'cheap-module-eval-source-map',
    cacheBusting: true,

    cssSourceMap: true
  }
}

今天突然不行了,解決辦法:

"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --host 192.168.x.xxx",
// 修改的是本地的ip 

再進行重新運行一下 npm install


npm run dev 運行一下就可以了

//瀏覽器裏面輸入
http://192.168.xx.xx:8080/index

自行備註,也希望可以幫到你。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章