vue jsonp封裝
阿新 • • 發佈:2019-01-02
import originJSONP from "jsonp"; export default function jsonp(url,data,option){ url += (url.indexOf("?")<0?"?":"&")+params(data); return new Promise((resolve,reject)=>{ originJSONP(url,option,(err,data)=>{ if(!err){ resolve(data); }else{ reject(err); } }) }); } function params(data){ let url=""; for(var i in data){ let value =data[i]!==undefined?data[i]:""; url+=`&${i}=${encodeURIComponent(value)}`; } return url?url.substring(1):""; }