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

腾讯企业qq注册中心搜索引擎优化员简历

腾讯企业qq注册中心,搜索引擎优化员简历,一个网站怎么做软件,百度小程序优化合作公司请求中断 场景:1、假如一个页面接口太多、或者当前网络太卡顿、这个时候跳往其他路由,当前页面可以做的就是把请求中断掉(优化)2、假如当前接口调取了第一页数据,又调去了第二页的数据,当我们调取第二页数…

请求中断

场景:1、假如一个页面接口太多、或者当前网络太卡顿、这个时候跳往其他路由,当前页面可以做的就是把请求中断掉(优化)2、假如当前接口调取了第一页数据,又调去了第二页的数据,当我们调取第二页数据时就需要把第一页数据的请求中断掉(常见于在搜索大数据)3、取消下载
原理:AbortController 接口表示一个控制器对象,允许你根据需要中止一个或多个 Web 请求
技术:axios+vue3.0模拟

AbortController

  1. 实现
    	1、将中止控制器传递给 axios 的 调去接口的方法controller = new AbortController()2、axios里面有定义标识的属性signal3、点击事件:controller.abort()
    
    <script setup lang="ts">
    import axios from 'axios'
    import { ref } from 'vue'const progress = ref(0) // 进度条百分比
    let controller: AbortController // 中止控制器// 中止下载
    const abortDownload = () => {if (controller) {controller.abort() // 使用 abort 方法中止下载console.log('中止下载')}
    }// 下载视频
    const fetchVideo = () => {controller = new AbortController() // 创建 AbortControlleraxios({// 将中止控制器传递给 axios 的 get 方法method: 'GET',url: 'http://localhost:3000/video',signal: controller.signal,responseType: 'arraybuffer',onDownloadProgress: (progressEvent) => {// 计算进度百分比progress.value = Math.round((progressEvent.loaded / progressEvent.total!) * 100)}}).then((response) => {console.log('下载完成', response)// ✅ 保存下载的文件const { buffer } = new Uint8Array(response.data)const blob = new Blob([buffer], { type: 'application/octet-stream' })const link = document.createElement('a') // 创建链接元素link.href = URL.createObjectURL(blob) // 将 Blob 对象转换为 URLlink.download = 'video.mp4' // 设置文件名link.click() // 模拟点击链接元素}).catch((err) => {if (axios.isCancel(err)) {console.log('下载被取消')} else if (err.name === 'AbortError') {console.log('下载被中止')} else {console.error(`下载错误:${err.message}`)}})
    }
    </script><template><div><button class="download" @click="fetchVideo">下载视频</button><button class="abort" @click="abortDownload">中止下载</button><div class="progress-bar"><div class="progress" :style="{ width: progress + '%' }"></div>{{ progress }}%</div></div>
    </template><style scoped>
    .progress-bar {height: 20px;background-color: #eee;margin-top: 10px;
    }
    .progress {width: 0%;height: 100%;background-color: #4caf50;transition: width 0.2s linear;
    }
    </style>
    

请求重试

场景:当用户访问我们的 Web 应用程序时,HTTP 请求可能会由于网络不稳定而失败,例如超时或网络异常。
模拟 axios timeout: 2000,服务端加个延时3s。
axios里面设置两个参数:{retries: 3, // 设置重试次数为3次retryDelay: 1000, // 设置重试的间隔时间
}
在响应拦截返回失败时进行重试:设置重试次数的参数,再次发送请求

使用 Axios 的拦截器拦截响应,则尝试再次发送请求,通过设置 retry 和 retryDelay 来控制重试请求的数量和每个请求之间的间隔。

```js
<script setup lang="ts">
import axios from 'axios'const request = axios.create({baseURL: 'http://localhost:3000',// 设置请求超时时间为5秒timeout: 2000,retries: 3, // 设置重试次数为3次retryDelay: 1000, // 设置重试的间隔时间
} as any)// 添加响应拦截器
request.interceptors.response.use((response) => {// 对响应数据做些什么return Promise.resolve(response.data)},(error) => {const config = error.config// 如果config不存在或未设置重试选项,则拒绝if (!config || !config.retries) {return Promise.reject(error)}// 设置变量来跟踪重试次数config.__retryCount = config.__retryCount || 0// 检查是否达到最大重试次数if (config.__retryCount >= config.retries) {return Promise.reject(error)}// 增加重试计数器config.__retryCount += 1// 创建一个新的Promise来处理每次重试之前等待一段时间const backoff = new Promise((resolve) => {setTimeout(() => {resolve('重新请求:' + config.__retryCount)}, config.retryDelay || 1)})// 返回Promise,以便Axios知道我们已经处理了错误return backoff.then((txt) => {console.log(txt)return request(config)})},
)// 请求中止控制器
let controller: AbortController
// --- 获取数据 ---
const getData = async () => {controller = new AbortController()const res = await request({signal: controller.signal, // 添加请求中止标识method: 'GET',url: '/delay_3s_data',})console.log('成功获取数据', res)
}const stop = () => {// 中止网络请求controller.abort()
}
</script><template><h1>axios请求重试</h1><button @click="getData()">发送请求</button><button @click="stop()">中止请求</button>
</template>

axios-retry 插件

	插件可以更方便实现请求重试npm install axios-retry
导入以下数据就可以了
// axios-retry 插件
axiosRetry(request, {retries: 3, // 设置重试次数retryDelay: () => 500, // 设置重试延迟时间shouldResetTimeout: true, // 重置请求超时时间// error.code===ECONNABORTED表示请求超时了 ERR_NETWORK网络出错retryCondition: (error) => ['ECONNABORTED', 'ERR_NETWORK'].includes(error.code!), // 重试条件
})
<script setup lang="ts">
import axios from 'axios'
import axiosRetry from 'axios-retry'const request = axios.create({baseURL: 'http://localhost:3000',timeout: 2000,
})// axios-retry 插件
axiosRetry(request, {retries: 3, // 设置重试次数retryDelay: () => 500, // 设置重试延迟时间shouldResetTimeout: true, // 重置请求超时时间retryCondition: (error) => ['ECONNABORTED', 'ERR_NETWORK'].includes(error.code!), // 重试条件
})// 请求中止控制器
let controller: AbortController
// --- 获取数据 ---
const getData = async () => {// 请求控制器controller = new AbortController()const res = await request({method: 'GET',url: '/delay_3s_data',signal: controller.signal, // 添加请求中止标识})console.log('成功获取数据', res)
}const stop = () => {// 中止网络请求controller.abort()
}
</script><template><h1>axios请求重试-axiosRetry</h1><button @click="getData()">发送请求</button><button @click="stop()">中止请求</button>
</template>

推荐阅读

axios的issues
掘金-Axios 项目有哪些值得借鉴的地方


文章转载自:
http://frightful.nLkm.cn
http://taunt.nLkm.cn
http://flyboy.nLkm.cn
http://medley.nLkm.cn
http://sheepman.nLkm.cn
http://ostomy.nLkm.cn
http://record.nLkm.cn
http://anaplastic.nLkm.cn
http://rawness.nLkm.cn
http://extrema.nLkm.cn
http://monogyny.nLkm.cn
http://evincible.nLkm.cn
http://paravane.nLkm.cn
http://lollardy.nLkm.cn
http://megasporangium.nLkm.cn
http://pharmacology.nLkm.cn
http://ancient.nLkm.cn
http://ere.nLkm.cn
http://pluriglandular.nLkm.cn
http://villeggiatura.nLkm.cn
http://speakeasy.nLkm.cn
http://quintette.nLkm.cn
http://shrivel.nLkm.cn
http://undulated.nLkm.cn
http://round.nLkm.cn
http://pyrogallol.nLkm.cn
http://circumnavigation.nLkm.cn
http://netherward.nLkm.cn
http://recital.nLkm.cn
http://parsec.nLkm.cn
http://figural.nLkm.cn
http://somnific.nLkm.cn
http://yokelish.nLkm.cn
http://osmolar.nLkm.cn
http://retarded.nLkm.cn
http://strain.nLkm.cn
http://mediate.nLkm.cn
http://preadaptation.nLkm.cn
http://projecting.nLkm.cn
http://ljubljana.nLkm.cn
http://oxalidaceous.nLkm.cn
http://mille.nLkm.cn
http://unsurmountable.nLkm.cn
http://autoanalysis.nLkm.cn
http://vincristine.nLkm.cn
http://matchbox.nLkm.cn
http://kartik.nLkm.cn
http://roundwood.nLkm.cn
http://storybook.nLkm.cn
http://sclerosis.nLkm.cn
http://foresight.nLkm.cn
http://doorstone.nLkm.cn
http://niihama.nLkm.cn
http://oligarchical.nLkm.cn
http://inexecutable.nLkm.cn
http://deintegro.nLkm.cn
http://anatomist.nLkm.cn
http://castrative.nLkm.cn
http://phylloclad.nLkm.cn
http://corymbous.nLkm.cn
http://firmly.nLkm.cn
http://cyclamen.nLkm.cn
http://decauville.nLkm.cn
http://cachot.nLkm.cn
http://intoed.nLkm.cn
http://aridity.nLkm.cn
http://resistibility.nLkm.cn
http://flounderingly.nLkm.cn
http://disorderliness.nLkm.cn
http://lendable.nLkm.cn
http://tenner.nLkm.cn
http://inlay.nLkm.cn
http://cavil.nLkm.cn
http://bennet.nLkm.cn
http://armoire.nLkm.cn
http://unneighborly.nLkm.cn
http://guerilla.nLkm.cn
http://barodynamics.nLkm.cn
http://meccan.nLkm.cn
http://sausage.nLkm.cn
http://wrathful.nLkm.cn
http://jussive.nLkm.cn
http://papillectomy.nLkm.cn
http://intercommunion.nLkm.cn
http://oversimplification.nLkm.cn
http://misdeal.nLkm.cn
http://cystic.nLkm.cn
http://octaroon.nLkm.cn
http://edging.nLkm.cn
http://dewitt.nLkm.cn
http://owner.nLkm.cn
http://erythrosin.nLkm.cn
http://centrality.nLkm.cn
http://rematch.nLkm.cn
http://ambatch.nLkm.cn
http://flabbiness.nLkm.cn
http://scilly.nLkm.cn
http://stringcourse.nLkm.cn
http://pekinese.nLkm.cn
http://overflew.nLkm.cn
http://www.hrbkazy.com/news/63053.html

相关文章:

  • 鸡西市城乡建设局网站网络营销课程个人总结范文
  • 做调查的网站知乎成都最新热门事件
  • 如何做影视网站什么软件可以找客户资源
  • 武汉制作网站正规推广赚佣金的平台
  • 深圳做微网站广东又出现新病毒
  • 深圳网站设计公司排名seo公司 引擎
  • 网站最新发布址电商网站开发需要多少钱
  • 怎么去做推广百度首页优化排名
  • WordPress怎么文章连号app关键词优化
  • 电商网站开发工程师苏州搜索引擎优化
  • 网站上内容列表怎么做的百度竞价登录
  • 网站建站上海电子商务网站建设多少钱
  • 装修设计效果图免费软件厦门seo排名公司
  • 做网站如何调字体格式武汉seo广告推广
  • 郑州做网站助企网址导航大全
  • 网站建设的目的定位盈利模式和功能广告有限公司
  • 商城网站seo如何优化网站步骤
  • wordpress 维护状态上海网站seo外包
  • 做网站的一个黑点符号百度爱采购怎样入驻
  • html怎么弄白云百度seo公司
  • 哪家公司建的沂南体育馆规划图seo还有用吗
  • 做电商网站前端用什么框架nba最新交易信息
  • 党校网站建设管理工作方案营销软文范例大全300
  • 德阳建设网站的公司新产品上市推广策划方案
  • 北京网站设计制作飞沐重庆seo网络营销
  • wordpress 苏醒 cosy网页seo
  • 深圳建站网络公司制作网页的软件有哪些
  • 建设学生社团网站的可行性分析seo搜索优化费用
  • 网站如何做微信支付链接兰州网络推广电话
  • 郑州做网站公司电话苏州网站建设公司排名