【发布时间】:2020-08-28 17:22:54
【问题描述】:
我在从 svg 图像中删除特定类时遇到问题,我在 jsfiddle 中简化了我的代码
当我点击图像时,它会得到特定的类,但我无法通过重置按钮删除该类
html
<div id="app">
<img src = "https://simplemaps.com/static/demos/resources/svg-library/svgs/world.svg" class = "img-fluid" style= "width: 200px;" @click = "tap($event)">
</div><!-- there are some images, just to clarify, I simplified my code -->
<!-- when i click on image it gets particular class but i cant remove that very class by reset button -->
<button @click = "reset">
reset
</button>
css文件
.colorFilter{
filter: invert(43%) sepia(96%) saturate(1237%) hue-rotate(88deg) brightness(58%) contrast(139%);
}
vue
new Vue({
el: "#app",
data: {
},
methods: {
tap(event){
event.target.classList.add('colorFilter');
},
reset(){
const imgz = document.getElementsByTagName('img');
imgz.classList.remove('colorFilter');// i cant reset the images
}
}
})
谢谢
【问题讨论】:
-
您也可以使用动态类绑定,更多信息请参阅此参考vuejs.org/v2/guide/class-and-style.html#Object-Syntax
-
感谢您的回答@Tanvir,但根据文档,如果我将 true 分配给 isActive,所有图像都会获得该类,但我只希望点击的图像获得该类而不是所有图像跨度>
-
为每个图像分配一个唯一的 id 并通过方法参数发送 ut ,然后检查您传递的 id == 图像 id 和 isActive 是否为真 ,,,,如果满足条件然后分配类否则不
标签: laravel vue.js vuejs2 vue-component