# 安裝 npm install -g @vue/cli
# 查看已安裝版本
vue --version 或者 vue -V # 卸載 npm uninstall @vue/cli -g # 新建項目 vue create my-project # 項目啟動 npm run serve # 打包 npm run build
在項目根目錄新建文件 vue.config.js
module.exports = {
devServer: {
port: 8080, // 端口號
host: "localhost",
https: false, // https:{type:Boolean}
open: true, //配置自動啟動瀏覽器
// proxy: 'http://localhost:4000' // 配置跨域處理,只有一個代理
proxy: {
"/api": {
target: "<url>", //接口地址
ws: true, //是否代理websockets
changeOrigin: true // 設置同源 默認false,是否需要改變原始主機頭為目標URL
},
"/foo": {
target: "<other_url>"
}
} // 配置多個代理
},
lintOnSave: false // 關閉eslint代碼檢查
};
在引用的時候 直接 用‘/api’ 代替路徑