安裝:npm install axios --save
main.js 入口檔案中全域掛載(這里使用原型鏈掛載):
import axios from 'axios';
Vue.prototype.$http = axios;
config檔案夾下的index.js 配置服務器環境
module.exports = {
dev: {//開發服務器
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {//代理跨域
'/equipment/':{//公共前綴
target:'介面的公共域名部分',
changeOrigin:true//跨域
}
host: 'localhost',
port: 8080, //埠號可更改
autoOpenBrowser: false,//默認不自行打開瀏覽器
errorOverlay: true,//查詢錯誤
notifyOnErrors: true,//通知錯誤
poll: false, //輪詢監控
devtool: 'cheap-module-eval-source-map',//webpack提供的用來方便除錯的配置
cacheBusting: true,//快取破解
cssSourceMap: true//是否開啟cssSourceMap
},
build: {
index: path.resolve(__dirname, '../dist/index.html'),//編譯后index.html的路徑
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),//打包后的檔案根路徑
assetsSubDirectory: 'static',
assetsPublicPath: '/',//靜態資源的公開路徑,即真正的參考路徑
productionSourceMap: true,
devtool: '#source-map',
productionGzip: false,//生產環境壓縮代碼
productionGzipExtensions: ['js', 'css'],//定義壓縮檔案
bundleAnalyzerReport: process.env.npm_config_report//是否開啟打包后的分析報告
}
}
在vue頁面中應用:
this.$http.post('介面后綴名',{params}).then(res=>{
console.log(res)
}).catch(err=>{
console.log(err)
})
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/196375.html
標籤:python
上一篇:2020-10-29
