gpt4 book ai didi

javascript - 类型错误 : trying to access 'property' on undefined

转载 作者:太空宇宙 更新时间:2023-11-04 15:28:55 24 4
gpt4 key购买 nike

我遇到了一个奇怪的错误:当尝试显示状态变量时,vuejs 警告我:渲染函数中出现错误:“TypeError:无法读取未定义的属性‘ token ’”

我的状态如下所示(在 vuejs 扩展中):

room:Object
details:Object
game_id:"1"
id:914527404
max_users:5
messages:Array[0]
token:"ef6464692f4cce187fe129d7"
user:Array[1]
messages:Array[0]
users:Array[1]

尽管出现错误,HTML 仍然可以正确呈现:

<button id="copySharingLink" type="button" class="btn btn-primary waves-effect waves-light" v-bind:data-token="room.details.token">some text</button>

变成了

<button id="copySharingLink" type="button" data-token="ef6464692f4cce187fe129d7" class="btn btn-primary waves-effect waves-light">some text</button>

我不知道如何消除这个错误,因为它正在工作。

最佳答案

有时 roomroom.details 尚未设置,此时可能会抛出错误。

尝试更改此代码...

v-bind:data-token="room.details.token"

...对此:

v-bind:data-token="room.hasOwnProperty('details') ? room.details.token : ''"

关于javascript - 类型错误 : trying to access 'property' on undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44969568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com