vue中使用switch,但是switch语句没有被执行

这里有一锅小兔叽 2019-03-14 11:42:23
for (var i = 0; i < $('.settingUpAccounts_left_li').length; i++) {
if (i == index) {
$('.settingUpAccounts_left_li')[i].setAttribute('class','settingUpAccounts_left_li addbackground');
let leftCont = $('.settingUpAccounts_left_li')[i].innerHTML;
switch(leftCont){
case "登录日志":
console.log(leftCont);
this.showLandingLog = true;
this.showChangPassword = false;
break;
case "修改密码":
this.showLandingLog = false;
this.showChangPassword = true;
break;
}
}else {
$('.settingUpAccounts_left_li')[i].setAttribute('class','settingUpAccounts_left_li');
}
}

用的是vue,在一个点击事件中对leftCont进行了判断,leftCont的值能拿到,但是switch语句完全没有被执行。
...全文
2329 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我拿leftCont的值是用的innerHTML: let leftCont = $('.settingUpAccounts_left_li')[i].innerHTML; 换成innerText就好了: let leftCont = $('.settingUpAccounts_left_li')[i].innerText;
風灬雲 2019-03-14
  • 打赏
  • 举报
回复

switch(leftCont){
              case "登录日志":
                console.log(leftCont);
                this.showLandingLog = true;
                this.showChangPassword = false;
                break;
              case "修改密码":
                this.showLandingLog = false;
                this.showChangPassword = true;
                break;
              default:
                 console.log(leftCont);
                 break;
            }
最后面加上default看看是没有进switch还是没有和case匹配上

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧