类型错误: 尝试访问未定义的'property'



我遇到了一个奇怪的错误:当尝试显示状态变量时,vuejs 警告我: 呈现函数中的错误:"类型错误:无法读取未定义的属性'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 : ''"

最新更新