如上图,我点击右上角的圆,下面四个圆出现,但问题时我第一次点击不起作用,要点第二下才会出现,是什么原因?
<div class="main_top">
<div class="top_img1" @click="appear()"></div>
<div id="eject1"></div>
<div id="eject2"></div>
<div id="eject3"></div>
<div id="eject4"></div>
</div>
appear() {
let eject1 = document.getElementById("eject1");
let eject2 = document.getElementById("eject2");
let eject3 = document.getElementById("eject3");
let eject4 = document.getElementById("eject4");
if (eject1.style.display == "none" && eject2.style.display == "none" &&
eject3.style.display == "none" && eject4.style.display == "none"
) {
eject1.style.display = "block";
eject2.style.display = "block";
eject3.style.display = "block";
eject4.style.display = "block";
} else {
eject1.style.display = "none";
eject2.style.display = "none";
eject3.style.display = "none";
eject4.style.display = "none";
}
},
不要在vue里面过度依赖jquery或者直接性的操作Dom
下面是合理写法