關於vue-cli的本地開發 run dev

啓動

開發的時候啓動webpack熱替換html

npm run dev

端口

默認端口號是8080
若是但願修改端口號,則進入~\config\index.js,修改dev下的port爲但願啓動的端口號前端

例如:  port: 80,

跨域

webpack+Express

進入~\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

Fetch.js

參考地址: http://wwsun.github.io/posts/fetch-api-intro.htmlweb

ngrok

相關文章
相關標籤/搜索