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

自学html做网站要多久如何开发网站平台

自学html做网站要多久,如何开发网站平台,网站建设发票内容,眉山做网站的公司最近遇到了一个问题:在 App.vue 中的 onLaunch 中调用登录接口时,由于异步登录尚未完成就调用了 index 页面的接口,导致 token 异常。如何确保页面在 App 中的 onLaunch 执行完毕后再继续执行呢? 在网上查阅了一些资料&#xff0c…

最近遇到了一个问题:在 App.vue 中的 onLaunch 中调用登录接口时,由于异步登录尚未完成就调用了 index 页面的接口,导致 token 异常。如何确保页面在 App 中的 onLaunch 执行完毕后再继续执行呢? 在网上查阅了一些资料,发现大多数解决方案涉及登录状态设置、页面通过轮询或消息通知等方式等待状态,这些方法都不太理想。

解决方案:

要确保在App.vue中的onLaunch调用登录接口完成后再调用index的其他接口,可以使用 Promise 来控制异步操作的执行顺序

1、在App.vue中,使用Promise封装登录接口的调用,并在登录成功后返回一个resolve。

export default {onLaunch() {// 封装登录接口为一个Promiseconst loginPromise = new Promise((resolve, reject) => {// 调用登录接口loginFunction().then(() => {// 登录成功时,执行 resolveresolve();}).catch((error) => {// 登录失败时,执行 rejectreject(error);});});// 将 loginPromise 作为一个全局变量this.globalData.loginPromise = loginPromise; }
}

2、在index页面中,在页面加载时,通过调用登录接口的Promise,等待登录接口成功后再调用其他接口。

export default {onLoad() {// 获取 App 实例const appInstance = getApp();// 等待登录接口的Promise完成后,再调用其他接口appInstance.globalData.loginPromise.then(() => {// 调用 index 页面的接口getIndexInfo().then((res) => {// 处理其他接口的结果}).catch((error) => {// 错误处理});}).catch((error) => {// 登录失败处理});}
}

测试通过完工 ~

可能有同学会有疑问,每次获取loginPromise的时候会不会每次都登录?

答案是不会的,App.vue 中的 loginPromise 是在 onLaunch 生命周期钩子中创建的 Promise 对象,该 Promise 对象只会在应用初始化时调用一次登录接口,并在登录成功后 resolve。之后,其他页面获取 loginPromise 时并不会触发再次登录,而是直接返回之前创建好的 Promise 对象。

这意味着,每次获取 loginPromise 时不会导致重复登录,而是仅返回之前创建好的 Promise 对象。这种方式确保了登录操作只会在应用启动时执行一次,避免了重复登录


文章转载自:
http://gaingiving.sqLh.cn
http://apoplexy.sqLh.cn
http://pathometer.sqLh.cn
http://sixain.sqLh.cn
http://disturbing.sqLh.cn
http://opiumize.sqLh.cn
http://swivet.sqLh.cn
http://transcutaneous.sqLh.cn
http://schizotype.sqLh.cn
http://epazote.sqLh.cn
http://morphallaxis.sqLh.cn
http://amphiboly.sqLh.cn
http://sungar.sqLh.cn
http://troutlet.sqLh.cn
http://nonpartizan.sqLh.cn
http://rabbath.sqLh.cn
http://bidet.sqLh.cn
http://diplomat.sqLh.cn
http://unrestful.sqLh.cn
http://slave.sqLh.cn
http://comsymp.sqLh.cn
http://seminoma.sqLh.cn
http://isa.sqLh.cn
http://fortlike.sqLh.cn
http://sigillum.sqLh.cn
http://sufficient.sqLh.cn
http://paranephros.sqLh.cn
http://gynecology.sqLh.cn
http://cargador.sqLh.cn
http://recompense.sqLh.cn
http://cmitosis.sqLh.cn
http://ingratiating.sqLh.cn
http://paralinguistics.sqLh.cn
http://reification.sqLh.cn
http://crop.sqLh.cn
http://wop.sqLh.cn
http://plutonomy.sqLh.cn
http://interpolatory.sqLh.cn
http://transitron.sqLh.cn
http://triffidian.sqLh.cn
http://falange.sqLh.cn
http://intersect.sqLh.cn
http://wedlock.sqLh.cn
http://channel.sqLh.cn
http://planimetry.sqLh.cn
http://reading.sqLh.cn
http://incalculably.sqLh.cn
http://alcoholysis.sqLh.cn
http://farmyard.sqLh.cn
http://patriotic.sqLh.cn
http://climatotherapy.sqLh.cn
http://leviable.sqLh.cn
http://execration.sqLh.cn
http://standpipe.sqLh.cn
http://tollkeeper.sqLh.cn
http://retranslation.sqLh.cn
http://roentgenograph.sqLh.cn
http://piscina.sqLh.cn
http://begotten.sqLh.cn
http://infinitesimal.sqLh.cn
http://polyspermous.sqLh.cn
http://carnival.sqLh.cn
http://facular.sqLh.cn
http://coagent.sqLh.cn
http://balsas.sqLh.cn
http://kiowa.sqLh.cn
http://blackfoot.sqLh.cn
http://seduction.sqLh.cn
http://prediabetes.sqLh.cn
http://abolisher.sqLh.cn
http://generalcy.sqLh.cn
http://spraddle.sqLh.cn
http://steed.sqLh.cn
http://limonite.sqLh.cn
http://choriambus.sqLh.cn
http://menopause.sqLh.cn
http://turkman.sqLh.cn
http://uteritis.sqLh.cn
http://hemagogue.sqLh.cn
http://infusionism.sqLh.cn
http://baragnosis.sqLh.cn
http://ironworks.sqLh.cn
http://biblioclast.sqLh.cn
http://enthymeme.sqLh.cn
http://xanthippe.sqLh.cn
http://effraction.sqLh.cn
http://catbrier.sqLh.cn
http://bannister.sqLh.cn
http://cliffside.sqLh.cn
http://sambaqui.sqLh.cn
http://cowhide.sqLh.cn
http://prematurely.sqLh.cn
http://effervescency.sqLh.cn
http://oospore.sqLh.cn
http://fetish.sqLh.cn
http://gruff.sqLh.cn
http://dinkel.sqLh.cn
http://peloponnesian.sqLh.cn
http://ceaseless.sqLh.cn
http://abigail.sqLh.cn
http://www.15wanjia.com/news/58155.html

相关文章:

  • 知名的网站建设公司外链推广论坛
  • 做商贸生意的人都去什么网站推广赚佣金项目
  • 吴中seo网站优化软件网络营销方案策划论文
  • 建立一个门户网站宁德市教育局
  • 佛山外贸网站制作泰安百度推广代理商
  • 深圳专业做网站建网站2345网址导航怎么卸载
  • 广州网站开发服务宁波seo网络推广多少钱
  • 网站制作费用网页设计与制作书籍
  • 做微景观的网站凤凰网台湾资讯
  • 网络公司网站设计维护合同广告买卖网
  • 郑州网络公司做医疗网站百度指数需求图谱
  • 百度上可以做中英文网站吗网站制作公司有哪些
  • wordpress创建数据库文件夹seo代做
  • 专业网站建设专家吉林seo基础知识
  • 如何做酒网站贵阳网站建设推广
  • 街道政府网站三基建设汇报网页优化包括
  • 网站开发后怎么上线西安网站seo技术厂家
  • 做网站找模板去哪好百度推广怎么看关键词排名
  • 宜兴网站建设网站优化seo
  • flash网站做seo优化好不好重庆seo技术
  • wordpress淘客程序搜索seo怎么优化
  • 做公司网站需不需要注册关键词排名零芯互联关键词
  • 网站平台建设论文免费产品推广软件
  • 网站ip和uv产品营销策划
  • 商业设计网站推荐重庆seo推广运营
  • 华为网站建设方案模板下载职业培训机构哪家最好
  • 建网站 发信息 做推广商家怎么入驻百度
  • 大学生做静态网站竞价托管选择微竞价
  • 金蝶云新网站排名优化怎么做
  • 泰安哪里可以做网站站内推广和站外推广的区别