vue-cli3.0添加axios 插件

添加axios 插件

  • vue add axios
  • src/main.js添加下列內容
Object.defineProperty(Vue.prototype, '$http', {
    value: axios
})
  • 根目錄新建vue.config.js
module.exports = {
    devServer: {
        proxy: {//如需跨域請求多個域名,在此對象進行擴展便可
            '/apis': {
                target: 'http://www.***.com/',
                ws: true,
                changeOrigin: true,
                pathRewrite: {
                    '^/apis': ''
                }
            },
            ...
        }
    }
}
  • (應用實例前重啓服務器)vue組件
this.$http.post("/apis/<UrlPath>",{
	"pageNum": 1,
    "pageSize": 5,
     "cityId": "",
}).then(res=>{
	console.log(res)
})
相關文章
相關標籤/搜索