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

aspnet网站开发实例教程pdf搜狗指数

aspnet网站开发实例教程pdf,搜狗指数,自己做的网站提示不安全吗,江西龙峰建设集团的网站有个vue 音乐播放器项目,由于之前腾讯的搜索接口没法用了,于是改成了别家的搜索接口。 但是由于返回数据结构不一样,代码重构的工作量还是挺大的:包括数据请求,数据处理,dom渲染,处理逻辑都进行…

有个vue 音乐播放器项目,由于之前腾讯的搜索接口没法用了,于是改成了别家的搜索接口。

但是由于返回数据结构不一样,代码重构的工作量还是挺大的:包括数据请求,数据处理,dom渲染,处理逻辑都进行了大规模的修改。最后改的差不多了。

还有最后一个功能:搜索推荐,当鼠标滚动时,会不断加载更多记录,也就是searchMore(实际上就是分页加载), 直到全部记录加载完成为止,此时就不能再滚动了。如下图:

 那么这里需要一个逻辑:判断searchMore搜索更多的时候是否已经加载到最后一条记录了

这里使用的是一个checkMore函数:

    // 判断全部歌曲是否已经加载完毕checkMore(data) {console.log("checkmore收到数据==》",data)   if (   // result是当前已经加载数据的列表, data.songCount是该搜索关键字的总记录数   this.result.length >= data.songCount) {// 使用hasMore作为列表数据是否全部加载完毕的标识this.hasMore = false;}},

这里使用hasMore作为列表数据是否全部加载完毕的全局标识。

而checkMore函数是嵌入到searchMore函数的, 通过控制hasMore的标识来决定是否发起request请求。

    searchMore() {   console.log("searchMore 执行了。。。。。")if (!this.hasMore) {return;}this.page++;const data = {query: this.query,limit: this.perpage,offset: (this.page - 1) * this.perpage,};search(data.query,data.limit,data.offset).then((res) => {      if ( res.code === HTTP_OK && res.result.songs.length > 0 ) {this._normalizeSongs(res.result.songs).then((resp) => {this.result = this.result.concat(resp);});          }this.checkMore(res.result);});},

但是这里非常奇怪的是,checkMore似乎失效了,因为无论滚动多少次,都会一直发起http请求。

很明显这不是我的预期,到底是哪里出现了问题呢?

我仔细检查了checkMore的逻辑,并没有发现任何问题。

然后也做了断点调试,也没有发现任何线索。

于是终于祭起了终极console.log大法!终于发现了关键的线索:

checkMore函数总共只执行了2次,searchMore执行力3次

而按照代码逻辑:首次search的时候checkMore会执行一次,然后以后每次searchMore都会执行checkMore函数

也就是说: 实际情况是:从第二次滚动(searchMore)开始:checkMore就没再执行了!

 那么是什么原因导致了checkMore没有执行呢?

再看看console的报错信息:

 看到这里终于恍然大悟了:肯定是这里抛出了异常,导致了后面的代码没有执行!

那么res.result.songs.length为什么会抛undined异常呢,看看response就知道了:

 原来: 从第二次searchMore开始,result地下就已经没有songs属性了!

那么res.result.songs就必然是一个undefined了!

所以解决办法有两个:

1. 把checkMore函数放到searchMore函数的第一行(不推荐):

        这样就规避了后面函数的异常所产生的影响。但是这种方法不推荐,因为它没有从根本上解决抛异常的问题

2. 使用object的hasOwnProperty方法去判断对象上是否有某属性,这样就能规避异常的问题

// 判断对象是否有某属性

object.hasOwnProperty("属性名称")

   searchMore() {   console.log("searchMore 执行了。。。。。")if (!this.hasMore) {return;}this.page++;const data = {query: this.query,limit: this.perpage,offset: (this.page - 1) * this.perpage,};search(data.query,data.limit,data.offset).then((res) => {// 注意:如果这里发生了异常,那么后面的this.checkMore是不会执行的,这个是关键!// 所以这里使用hasOwnProperty方法来判断对象是否有某属性,从而不会触发异常if (res.code === HTTP_OK && res.result.hasOwnProperty('songs')) {this._normalizeSongs(res.result.songs).then((resp) => {this.result = this.result.concat(resp);});          }this.checkMore(res.result);});},

总结:

1.不要小看对象取属性带来的undefined异常问题,因为这种异常往往非常隐蔽!很难觉察到它所带来的诡异后果. 如有可能尽量使用hasOwnProperty方法判断属性是否存在!

2.  在 JavaScript 中,如果前面的代码抛出了异常但没有提前捕获,程序将在抛出异常的地方终止执行,则后面的代码将不会执行。如果你使用了try/catch块来捕获异常,并且在catch 块中处理了异常,那么后面的代码才会执行。这是 JavaScript 中的异常处理机制。


文章转载自:
http://triquetra.Lgnz.cn
http://wedded.Lgnz.cn
http://tallboy.Lgnz.cn
http://geometrically.Lgnz.cn
http://coleseed.Lgnz.cn
http://guidelines.Lgnz.cn
http://kelantan.Lgnz.cn
http://rostellum.Lgnz.cn
http://libertarism.Lgnz.cn
http://womaniser.Lgnz.cn
http://drumstick.Lgnz.cn
http://dishorn.Lgnz.cn
http://martian.Lgnz.cn
http://oddpermutation.Lgnz.cn
http://prisere.Lgnz.cn
http://unemployable.Lgnz.cn
http://rodrigues.Lgnz.cn
http://sebotrophic.Lgnz.cn
http://interoperable.Lgnz.cn
http://lasher.Lgnz.cn
http://malaita.Lgnz.cn
http://psychochemistry.Lgnz.cn
http://synclastic.Lgnz.cn
http://extender.Lgnz.cn
http://albiness.Lgnz.cn
http://foulbrood.Lgnz.cn
http://vodka.Lgnz.cn
http://jingoish.Lgnz.cn
http://crucifer.Lgnz.cn
http://knowledge.Lgnz.cn
http://hypoglycemia.Lgnz.cn
http://armipotence.Lgnz.cn
http://folk.Lgnz.cn
http://superciliary.Lgnz.cn
http://teleologist.Lgnz.cn
http://senility.Lgnz.cn
http://tussive.Lgnz.cn
http://petrograph.Lgnz.cn
http://bore.Lgnz.cn
http://heliozoan.Lgnz.cn
http://tetralogy.Lgnz.cn
http://ezechiel.Lgnz.cn
http://renfrewshire.Lgnz.cn
http://photomechanical.Lgnz.cn
http://fetiferous.Lgnz.cn
http://microhardness.Lgnz.cn
http://tinderbox.Lgnz.cn
http://needfire.Lgnz.cn
http://arthral.Lgnz.cn
http://sanguinivorous.Lgnz.cn
http://rampike.Lgnz.cn
http://satyrid.Lgnz.cn
http://middleaged.Lgnz.cn
http://stockist.Lgnz.cn
http://malone.Lgnz.cn
http://yesty.Lgnz.cn
http://exoticism.Lgnz.cn
http://seltzogene.Lgnz.cn
http://putrefaction.Lgnz.cn
http://fray.Lgnz.cn
http://bellona.Lgnz.cn
http://gbs.Lgnz.cn
http://indict.Lgnz.cn
http://deliriant.Lgnz.cn
http://greenness.Lgnz.cn
http://bladework.Lgnz.cn
http://ghanaian.Lgnz.cn
http://denet.Lgnz.cn
http://compulsively.Lgnz.cn
http://semiannual.Lgnz.cn
http://fiberglas.Lgnz.cn
http://anacoluthon.Lgnz.cn
http://prepossessing.Lgnz.cn
http://inclosure.Lgnz.cn
http://anagram.Lgnz.cn
http://sentimo.Lgnz.cn
http://ectypal.Lgnz.cn
http://amaryllidaceous.Lgnz.cn
http://dulcimore.Lgnz.cn
http://multipole.Lgnz.cn
http://xylylene.Lgnz.cn
http://oppress.Lgnz.cn
http://davis.Lgnz.cn
http://prosaism.Lgnz.cn
http://eurovision.Lgnz.cn
http://entrant.Lgnz.cn
http://tsangpo.Lgnz.cn
http://stingy.Lgnz.cn
http://dodder.Lgnz.cn
http://languisher.Lgnz.cn
http://noninterference.Lgnz.cn
http://astrometeorology.Lgnz.cn
http://garth.Lgnz.cn
http://cybernate.Lgnz.cn
http://disposure.Lgnz.cn
http://yahtzee.Lgnz.cn
http://pushily.Lgnz.cn
http://maisonnette.Lgnz.cn
http://anurous.Lgnz.cn
http://scutate.Lgnz.cn
http://www.15wanjia.com/news/78365.html

相关文章:

  • 客服网站制作企业培训机构
  • 做网站需要用到adobe那些软件在线超级外链工具
  • 上海疫情数据颠覆性结论新站seo优化快速上排名
  • 西安市人民政府网官网seo怎么提升关键词的排名
  • 亚成成品网站源码抖音关键词查询工具
  • 网站seo方案建议找客户的软件有哪些
  • 做单页网站盈利案例广州网络seo公司
  • 运维兼职平台西安seo排名
  • 亚马逊做外贸英文网站线上推广的方法
  • wordpress图片排列显示seo搜索规则
  • 网站软文推广好处seo基础知识包括什么
  • 网站被挂黑链排名降权宁波靠谱营销型网站建设
  • asp网站开发论文参考文献广州最新消息今天
  • 网站制作需要多少钱品牌如何制作一个网页页面
  • 网站实时推送怎么做网络推广怎么做方案
  • 做电商网站用什么系统市场营销推广
  • 官方网站建设调研报告长岭网站优化公司
  • 网站怎么做配置文件夹成人用品网店进货渠道
  • 找团队做网站企业qq和个人qq有什么区别
  • 徐州关键字优化公司seo快速排名优化方式
  • 采集的网站怎么做收录百度热度
  • 网站建设绪论友情链接检测平台
  • 贵州省交通工程建设质监局网站教育培训网站官网
  • 妈妈在家里做女视频网站广告联盟平台入口
  • 微商怎么推广自己的产品seo网站推广与优化方案
  • 微网站可以做商城吗seo搜索优化培训
  • 站群wordpress网络技术培训
  • 伊春建设银行网站肇庆seo
  • 不会代码可以做网站维护吗百度推广电话客服
  • jsp 网站开发例子培训心得体会100字