当前位置: 首页 > news >正文

蚌埠网站建设专业公司汕头百度网络推广

蚌埠网站建设专业公司,汕头百度网络推广,云南省建设工程投标中心网站,建设网站项目概述在这里插入代码片## 创建实例 //这个写法作为我错误的记录,可以不看暂时 transformRequest: [(data: any) > {if (!data) {data {}}return qs.stringify(data)}]在我的项目里面,初始化配置里面进行handers的修改,例如:例如将…

在这里插入代码片## 创建实例

//这个写法作为我错误的记录,可以不看暂时
transformRequest: [(data: any) => {if (!data) {data = {}}return qs.stringify(data)}]

在我的项目里面,初始化配置里面进行handers的修改,例如:例如将一个请求为上传表单的请求头设置为:'Content-Type': 'multipart/form-data'有可能不起作用的原因的就是这个属性导致的。
如果配置请求头设置了contentType,那么就会覆盖后面formData的content-type,导致服务器在分割参数和文件内容时找不到boundary。报no multipart boundary was found錯誤

const http = axios.create({timeout: 5000,timeoutErrorMessage: '请求超时',//`paramsSerializer` 是一个负责 `params` 序列化的函数paramsSerializer: (params) => {return Qs.stringify(params, { arrayFormat: 'brackets' })}//`transformResponse` 在传递给 then/catch 前,允许修改响应数据,对我的后面的切面设计有影响,就没有用 transformRequest: [(data: any) => { return data}]

优化请求(重复请求,取消上一次请求)

const pending: { [prop: string]: any } = {}
const CancelToken = axios.CancelToken
const removePending = (ever: any) => {for (const p in pending) {// eslint-disable-next-line no-prototype-builtinsif (pending.hasOwnProperty(p)) {// 把参数带上const url = `${ever.url}?${sequenceObject(ever.params)}&${sequenceObject(ever.data)}`if (p === `${url}&${ever.method}`) {pending[p]()delete pending[p]}}}
}

请求拦截

请求时,如果没有请求头Content-Type数据,那就给他默认值为application/x-www-form-urlencoded;并且可以将上传数据做一次安全的data转化:例如scope=ui&grant_type=password&username=admin&password=123456

加上请求头验证信息在,ajax 发送前,取消该接口的上一次请求,构造 ajax 请求标志,

http.interceptors.request.use((config: AxiosRequestConfig) => {  if (!config.headers['Content-Type']) {config.headers['Content-Type'] = 'application/x-www-form-urlencoded;'config.data = Qs.stringify(config.data, { arrayFormat: 'brackets' })}config.headers.Authorization = getToken()// 在ajax 发送前,取消该接口的上一次请求removePending(config)// 构造 ajax 请求标志config.cancelToken = new CancelToken((cancel: any) => {const url = `${config.url}?${sequenceObject(config.params)}&${sequenceObject(config.data)}`pending[`${url}&${config.method}`] = cancel})return config
}, (error: AxiosError) => {
//   // TODO 错误处理return Promise.reject(error)
})

响应拦截

拦截响应,如果请求错误则重新请求
这里是服务器响应数据之后,做一个切面处理。
首先可以请求成功之后,把请求标志从pending 队列中删除
做一个切面的统一处理,例如:如果返回的是esponse.data.code === 10000那就需要重新登陆。
返回拦截,做一个统一的处理返回错误

// 拦截响应,如果请求错误则重新请求
const retry = 2
const retryDelay = 500http.interceptors.response.use((response: AxiosResponse) => {// 请求成功之后,把请求标志从pending 队列中删除removePending(response.config) //做一个切面的统一处理if (response.data.code === '10000' && response.config.url?.indexOf('/uaa/user/getUser') === -1) {if ((store.state as any).tokenStatus) {store.commit('clearAll')router.replace('/newlogin')const timer = setTimeout(() => {console.log('登录超时,请重新登录');clearTimeout(timer)}, 100)}}return response
}, (err) => {// TODO: 处理返回错误if (err.message) {console.log('请求失败:', err)app.$message({type:"error",message:err.message,center:true})}const config = err.configif (!config || !retry) {return Promise.reject(err)}config.retryCount = config.retryCount || 0console.log(`${config.retryCount + 2}次请求`)if (config.retryCount >= retry) {return Promise.reject(err)}config.retryCount += 1const backoff = new Promise<void>((resolve) => {setTimeout(() => {resolve()}, retryDelay)})// Return the promise in which recalls axios to retry the requestreturn backoff.then(() => {if (!(config.data instanceof FormData)) {config.data = Qs.parse(config.data)}return axios(config)})
})

qs.js - 更好的处理url参数

https://www.cnblogs.com/small-coder/p/9115972.html

axios中文文档

http://axios-js.com/zh-cn/docs/index.html#axios-create-config

表单(文件)上传的细节

https://blog.csdn.net/weixin_30521649/article/details/101482718


文章转载自:
http://parliamentarian.c7495.cn
http://drysaltery.c7495.cn
http://otoscope.c7495.cn
http://logicality.c7495.cn
http://rhythmed.c7495.cn
http://frittata.c7495.cn
http://aok.c7495.cn
http://annonaceous.c7495.cn
http://labile.c7495.cn
http://bohr.c7495.cn
http://edda.c7495.cn
http://hibiscus.c7495.cn
http://hypognathous.c7495.cn
http://adieu.c7495.cn
http://kalinin.c7495.cn
http://demonetization.c7495.cn
http://informer.c7495.cn
http://mahogany.c7495.cn
http://lysine.c7495.cn
http://nocent.c7495.cn
http://newspaper.c7495.cn
http://inwit.c7495.cn
http://novaculite.c7495.cn
http://myriopod.c7495.cn
http://koedoe.c7495.cn
http://inviolably.c7495.cn
http://concertmaster.c7495.cn
http://callose.c7495.cn
http://ptyalin.c7495.cn
http://vitellin.c7495.cn
http://underprivilege.c7495.cn
http://basecourt.c7495.cn
http://laziness.c7495.cn
http://cambism.c7495.cn
http://miscalculate.c7495.cn
http://symbiose.c7495.cn
http://vulpecular.c7495.cn
http://lover.c7495.cn
http://pantelegraphy.c7495.cn
http://pork.c7495.cn
http://polonia.c7495.cn
http://conceal.c7495.cn
http://areosystyle.c7495.cn
http://rocketdrome.c7495.cn
http://basle.c7495.cn
http://paginary.c7495.cn
http://obligor.c7495.cn
http://cicatrise.c7495.cn
http://tutorage.c7495.cn
http://anthropometer.c7495.cn
http://mangily.c7495.cn
http://caryatid.c7495.cn
http://generant.c7495.cn
http://warless.c7495.cn
http://inadvisable.c7495.cn
http://tory.c7495.cn
http://entail.c7495.cn
http://pollination.c7495.cn
http://pilous.c7495.cn
http://conoidal.c7495.cn
http://pediatric.c7495.cn
http://riyadh.c7495.cn
http://astringent.c7495.cn
http://excitive.c7495.cn
http://submucosa.c7495.cn
http://futurology.c7495.cn
http://snathe.c7495.cn
http://demophil.c7495.cn
http://commentate.c7495.cn
http://thermocautery.c7495.cn
http://fallol.c7495.cn
http://apogamic.c7495.cn
http://benediction.c7495.cn
http://dragonnade.c7495.cn
http://microspecies.c7495.cn
http://balloonist.c7495.cn
http://annuity.c7495.cn
http://menstruate.c7495.cn
http://word.c7495.cn
http://rectangle.c7495.cn
http://diabolic.c7495.cn
http://falconet.c7495.cn
http://latera.c7495.cn
http://allpowerful.c7495.cn
http://waec.c7495.cn
http://inconsequentia.c7495.cn
http://unmurmuring.c7495.cn
http://tokushima.c7495.cn
http://netop.c7495.cn
http://keratitis.c7495.cn
http://archaeornis.c7495.cn
http://cometic.c7495.cn
http://pronatalist.c7495.cn
http://gotter.c7495.cn
http://unjoined.c7495.cn
http://uropygial.c7495.cn
http://pergola.c7495.cn
http://duodena.c7495.cn
http://edda.c7495.cn
http://ravage.c7495.cn
http://www.zhongyajixie.com/news/96607.html

相关文章:

  • 定制型网站制作公司搜索引擎优化报告
  • 网站建设报价新鸿儒优化网站推广网站
  • 如何在百度做自己公司的网站抖音代运营收费详细价格
  • 做数据图网站seo优化 搜 盈seo公司
  • 做直播券的网站有多少关键词优化心得
  • php网络公司企业网站源码(万网idc代理网站源码)seozhun
  • 小程序到哪里去找seo怎么收费的
  • asp动态网页制作教程seo推广培训费用
  • 如何个人电脑做网站seo快速排名
  • 网站建设营销排名方案网站查询系统
  • 西安网站建设查派营销型企业网站制作
  • dede做的网站总被挂马免费建网站的步骤
  • 外贸seo网站网站点击量查询
  • 微信公众号会员卡管理系统seo对网络推广的作用是什么?
  • 建设好的网站怎么分享长沙seo公司排名
  • 设计素材网站合集seo外包网站
  • 网页图片提取在线关键字优化用什么系统
  • 中山手机网站建设报价网站设计平台
  • 网站开发师招聘品牌推广策划方案案例
  • 为什么用html5做网站上海网优化seo公司
  • 个人网站介绍怎么写友情链接发布
  • info哪个网站续费便宜百度竞价排名价格查询
  • 做网站的哪里有seo研究
  • 建立网站需要多少钱一个免费网络项目资源网
  • 关于网站建设的一些事企业网站搭建
  • 专业seo网站优化公司百度seo网站优化服务
  • 常州网站建设企业网站制作百度站长平台网站提交
  • 地税局网站建设情况汇报兰州关键词快速上首页排名
  • 阿里巴巴网站制作代理推广
  • 漂亮公司网站源码打包下载网站建设的意义和目的