vue 中使用axios 的方式
第一种
定义axios函数
a 文件
import axios from "axios"; export default axios.create({ baseURL:'接口', // headers:{'content-type':'application/json'} // application/x-www-form-urlencoded })
b 文件调用
import axios from "./axios"; export const colum = (obj)=>{ return axios.post('子接口',{ 参数 }) }
vue 文件 处理函数返回参数
colum({ 参数 }).then(res => { 处理返回数据 });
第二种
定义函数
pub.js
import $ from "jquery"; import axios from 'axios' _InitAxios(op) { axios({ url: op._url + op.ur, method: "post", data: JSON.stringify(op.data), headers: { "Content-Type": "application/json" } }) .then(res => { console.log('axios 访问返回数据', res) op.cbk(res.data); }) .catch(cat => {}); }
vue 文件调用
import $ from "jquery"; import axios from "axios"; import { pub } from "./assets/js/pub"; var op_data = { that: that, _url: ,// 总接口 ur: , // 具体接口 cbk: that.cb, // 回调 data: { } // 形参 }; pub._InitAxios(op_data); cb(res){ 处理返回参数 }
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦