開發的時候啓動webpack熱替換html
npm run dev
默認端口號是8080
若是但願修改端口號,則進入~\config\index.js
,修改dev
下的port
爲但願啓動的端口號前端
例如: port: 80,
進入~\config\index.js
,在dev
下的proxyTable
就是網址映射webpack
proxyTable: { '/api': { target: 'http://localhost:6060',//要跨域訪問的API域名 rewrite: function(req) { //能夠用正則方式替代掉,這樣往後 /api/xxx/xxx 之類的網址,就會自動匹配了 req.url = req.url.replace(/^\/api/, ''); } } }
這樣當你呼叫 /api
時:git
this.$http.get('/api')
就會幫你自動導向 http://localhost:8080/api
,是為了當 Server 和 前端 不在同個網域或是Port時,能夠方便調試,例如我 Server 在 localhost:6060
,前端在 localhost:5050
,就能夠直接調用 /api
,而不用每次都要加上完整網址
更多信息可參考: https://webpack.github.io/docs/webpack-dev-server.html#proxygithub
參考地址: http://wwsun.github.io/posts/fetch-api-intro.htmlweb