div点击时:focus等无法实现选中样式,可以使用动态class实现
html部分:
@click="handleView($event)"
CSS部分:
.active{
color: #fff;
border-right:3px solid;
background-color: #f0c195;
}
method部分:
methods:{
handleView: function (e) {
let currentClick = e.target;//当前点击
if( this.lastClick !== ""){//上次点击
this.lastClick.removeAttribute("class")
}
this.lastClick = currentClick;
currentClick.setAttribute("class","active");//添加class属性
}