php中文网 | cnphp.com

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 795|回复: 0

TypeError: Cannot set properties of undefined (setting ‘innerHTML‘)

[复制链接]

2871

主题

2881

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

UID
1
威望
0
积分
7283
贡献
0
注册时间
2021-4-14
最后登录
2024-9-19
在线时间
715 小时
QQ
发表于 2022-1-26 12:38:34 | 显示全部楼层 |阅读模式
Vue调用本地组件定义的变量,报错TypeError: Cannot set properties of undefined (setting ‘innerHTML‘),可能是回调函数内无法直接访问本地组件变量的原因。
以下图片显示的代码,在vue的data -> return中定义了contentList这个变量,但是在回调函数中,console.log(this.contentList),浏览器端报错TypeError: Cannot set properties of undefined (setting ‘innerHTML‘),是因为回调函数无法发现本地变量
image.png
解决方案:
通过const self = this的方式,在回调函数外先获取本地组件引用,然后在回调函数内再进行使用和操作。
image.png

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|php中文网 | cnphp.com ( 赣ICP备2021002321号-2 )

GMT+8, 2024-9-20 00:40 , Processed in 0.189425 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

申明:本站所有资源皆搜集自网络,相关版权归版权持有人所有,如有侵权,请电邮(fiorkn@foxmail.com)告之,本站会尽快删除。

快速回复 返回顶部 返回列表