【发布时间】:2020-03-07 12:19:55
【问题描述】:
我有三个组件我想触发位于overlay.vue 组件中的show() 方法,来自about.vue 组件
我是初学者,希望能得到你们的帮助
第一个是overlay.vue
<template>
<div class="overlay"></div>
</template>
<script>
export default {
name: "overlay",
methods: {
show() {
document.querySelector(".overlay").style.display = "block";
}
}
};
</script>
第二个是about.vue
<template>
<section class="about">
<div class="container">
<div class="row video">
<div class="col-lg-6 order-lg-1 order-2">
<img
class="dots img-fluid"
src="../assets/images/dots.svg"
alt="dots"
/>
<div class="video-wrapper">
<div class="video-img">
<img
class="img-fluid"
src="../assets/images/video.png"
alt="#"
/>
</div>
<div class="video-i">
<!-- ***************************************************************
***** this is where i want to trigger the method using this below a tag*****
*************************************************** -->
<a href="#"><i class="fas fa-play"></i></a>
</div>
</div>
</div>
</div>
</div>
</section>
</template>
第三个是父 app.vue,我在其中导入 about.vue 和 overlay.vue
<template>
<div id="app">
<overlay></overlay>
<about></about>
</div>
</template>
<script>
import overlay from "./components/overlay";
import about from "./components/about";
export default {
name: "App",
components: {
about,
overlay
}
};
</script>
【问题讨论】:
-
使用商店。在
show方法中,将存储值设置为true。然后在 about.vue 中,将显示状态绑定到要修改的 div 上。如果您在 vue 应用程序中进行 don 操作 (querySelector),那么您可能做错了什么。 -
我还是做不到。 :(((((((()
标签: javascript vue.js vuejs2