- 例如如下dom
<li class="del" @click="del($event)">删除</li>
- 因为js获取兄弟元素需要中转,所以先获取父元素,再获取子元素,移除className,再给当前dom添加className
const siblings = e.currentTarget.parentNode.children;for (let i = 0; i < siblings.length; i++) {if (siblings[i].classList.contains('active')) {siblings[i].classList.remove('active');}
}
e.currentTarget.classList.add('active')