if-statement - 如何处理 Vue 中返回未定义错误的渲染错误
问题描述
我有下面的代码在运行时引发未定义的错误,无论如何我可以捕获或使用条件格式吗?这是我到目前为止所做的:
<data-list
label='Group Name: '
:change="gotoGroups()"
></data-list> //this a search and select drop-down list
方法:
gotoGroups(){
if(this.$refs['groupName'].choice != 'undefined'){
//I have also tried (typeof this.$refs['groupName'].choice != 'undefined')
//do this
}
}
发出警告:
app.js:22462 [Vue 警告]:渲染错误:“TypeError:无法读取未定义的属性‘选择’”
两个都不行,怎么超越?
解决方案
你可以摆脱这个TypeError
。使用代码如下
if(this.$refs['groupName'] && this.$refs['groupName'].choice != 'undefined'){
//do this
}
要了解有关Short-circuit evaluation
您的更多信息,可以查看此资源
推荐阅读
- javascript - getElementById 其中 ID 增加 1
- rasa-nlu - 在 RASA 中处理多个用户输入
- java - 如何为 spring-kafka 创建的所有 MessageListenerContainers 设置 RecordInterceptor
- c - 当宏将值存储在自己的参数中时,这意味着什么?
- react-select - 使用 react-hook-form 进行反应选择
- ios - 我应该在ios的日记应用中使用什么类型的数据库?
- microservices - 如何在微服务架构中实现从多个服务中检索数据的查询?
- c# - 打开 Unity 项目时,卡在导入上
- github - 从 Cake 的 GitHub Pull Requests 访问目标分支名称
- r - 列标题包含示例信息我如何将它们分成 R 中的两列