微信小程序报错

TypeError: Cannot read property ‘replace’ of undefined

感觉代码是没有问题的;
刚开始:

let bg1 = this.myData.backgroundImage.replace("http://fast.hnzhilv.com/mingpian/bg", "");let url1 = item.url.replace("http://fast.hnzhilv.com/mingpian/%E5%90%8D%E7%89%87", "");if (bg1 == url1) {flag = true}

改良后:

if (this.myData.backgroundImage && item.url) {let bg1 = this.myData.backgroundImage.replace("http://fast.hnzhilv.com/mingpian/bg", "");let url1 = item.url.replace("http://fast.hnzhilv.com/mingpian/%E5%90%8D%E7%89%87", "");if (bg1 == url1) {flag = true}}

其实就是当它还没加载完的时候是null或者是undefined,所以就直接报错了,这里只需要判断一下就好了。
解决了!

TypeError: Cannot read property ‘replace‘ of undefined相关推荐

  1. 微信小程序[渲染层错误] TypeError: Cannot read property ‘replace‘ of undefined 【解决办法】

    微信小程序报错: [渲染层错误] TypeError: Cannot read property 'replace' of undefinedat rewritor (http://127.0.0.1 ...

  2. 微信小程序[渲染层错误] TypeError Cannot read property ‘replace‘ of undefined 【解决办法】

    微信小程序报错: [渲染层错误] TypeError: Cannot read property 'replace' of undefinedat rewritor (http://127.0.0.1 ...

  3. SharePoint 2013 Error - TypeError: Unable to get property 'replace' of undefined or null reference

    错误信息 TypeError: Unable to get property 'replace' of undefined or null referenceTypeError: Unable to ...

  4. 页面[components/listCard/listCard]错误: TypeError: Cannot read property ‘name‘ of undefined 问题解决

    页面[components/listCard/listCard]错误: TypeError: Cannot read property 'name' of undefined 这个问题非常的坑 因为我 ...

  5. chrome浏览器不能录音:Uncaught TypeError: Cannot read property ‘getUserMedia‘ of undefined解决方法

    Uncaught TypeError: Cannot read property 'getUserMedia' of undefined解决方法 javascript 打不开浏览器录音功能的问题解决方 ...

  6. jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' of undefined

    Jquery DataTable使用报这个错: jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' o ...

  7. VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法...

    data里面做了定义 在方法里面进行赋值 用 this.info = repos.data 数据可以请求到,但是会报错 TypeError: Cannot set property 'listgrou ...

  8. bug之bootstrap switch Uncaught TypeError: Cannot read property 'apply' of undefined

    2019独角兽企业重金招聘Python工程师标准>>> <input type="checkbox" name="my-switch" ...

  9. Vue页面加载使用二级属性的时候报错TypeError: Cannot read property ‘name‘ of undefined“

    <template v-if="tableData != undefined"><div><h3 style="padding:0px;te ...

最新文章

  1. 保存csv时, 不保留index
  2. [云炬创业基础笔记] 第四章测试12
  3. Android升级butterknife,Android组件化开发中使用Butterknife的坑
  4. webpack 入口文件 php,webpack的使用详解
  5. HDU - 3746 Cyclic Nacklace(KMP的next数组判循环节)
  6. C++ 模板全特化中的函数特化
  7. 杨强教授团队权威专著《联邦学习》问世,展现数据孤岛和数据保护难题破解之法
  8. 调用微信的扫一扫功能
  9. JavaScript简单入门教程学习篇
  10. java软件开发是什么_java常用的开发软件是什么
  11. 年薪百万不如狗?深圳的程序员才是买房界的黑天鹅!
  12. 商业方向的大数据专业_工业大数据应用的三大挑战和五大商业趋势
  13. labelme标记图像时JSON标签复制
  14. vue项目实现打印预览、生成(导出)文档功能
  15. LHS与RHS查询(已完结)
  16. python中的整数
  17. FL Studio水果编曲软件V20.0.3.542密钥序列号版
  18. gorm Preload主子表查询 学习笔记
  19. 饥荒专属服务器证书过期,饥荒TGP版存档丢失及证书不存在解决方法介绍
  20. 没有灵感头发都快抓掉了!推荐几款创意网站,让大脑灵光一动!

热门文章

  1. Linux cd命令cd、 cd ~、cd /、cd../、cd /home
  2. python 如何调试函数_使用函数 - python断点调试方法
  3. 智选假日酒店品牌创立三十周年;首家汉庭新品旗舰店落子天津;百胜中国西南供应链支持中心落户成都 | 美通企业周刊...
  4. 【Qt炫酷动画】0.Qt动画类简介
  5. 【Photoshop教程】非常酷的狐狸叫派对海报
  6. Python Class 类继承变量的使用方法
  7. 怎么将heic转换成jpg?
  8. Android Studio App开发之通知渠道NotificationChannel及给华为、小米手机桌面应用添加消息数量角标实战(包括消息重要级别的设置 附源码)
  9. 在python中安装一个nobug模块,让你的程序不在有bug
  10. 感染了恶意软件怎么办?