javascript - 如何在 vue.js 中的 v-if 中使用 toLowerCase()?
问题描述
在 vue.js 中,我有以下代码:
<q-btn @click="goEditMode" color="primary" icon="edit" label="Edit"
v-if="this.form.userName.toLowerCase() !== 'admin'" />
添加toLowerCase()后出现错误。
这是错误:
[Vue warn]: Error in render: "TypeError: Cannot read property 'toLowerCase' of undefined"
请帮助我,谢谢!
解决方案
发生此错误是由于undefined.toLowerCase()
.
看起来您正在运行toLowerCase
其父级中不存在的某些属性。
所以先检查是否this.form.userName
存在。
您可以执行类似的操作。
this.form.userName ? this.form.userName.toLowerCase() : ''
推荐阅读
- python-3.x - Selenium ActionChains 对 Mac 没有影响
- html - HTML CSS 添加下拉菜单
- html - CSS DIV 伸出另一个 DIV
- matlab - 在 MATLAB 中对坐标网格执行线性变换
- python - 使用请求时,我获取了 html,但所有 [š, č, ž,..] 字符都已更改
- python - 如何修复此 RuntimeError: size mismatch, m1: [64 x 103], m2: [550 x 50]
- python - 模块“matplotlib.cm”没有“蓝调”成员
- python - 复制和粘贴 Python 数组
- python - 如何将 168 个数据点转换为工作日的每小时绘图数据
- java - 为什么hibernate试图在数据库中找到一个实体而不是创建它?