[英]Modal component causing page refresh
I have a modal which only appears if the route is on a specific page named 'Item'.我有一个模式,仅当路线位于名为“项目”的特定页面上时才会出现。 For some reason, if I click a different view, it reloads the page.
出于某种原因,如果我单击不同的视图,它会重新加载页面。 Works perfectly fine on all the other routes except the one with a modal.
除了带有模态的路线外,在所有其他路线上都可以正常工作。 When I remove the modal it works as it should.
当我删除模态时,它可以正常工作。 Am I missing something?
我错过了什么吗? Should the modal component not be in the layout?
模态组件不应该在布局中吗?
Layout.vue:布局.vue:
<template>
<div>
<Modal v-if="this.$route.name === 'Item'" />
<Navbar />
<transition-group name="jumbo">
<Jumbotron :key="1" v-if="this.$route.path === '/'" />
<SecondaryJumbotron :key="2" v-if="this.$route.path !== '/'" />
</transition-group>
<transition appear name="page">
<router-view></router-view>
</transition>
<SideItems
v-if="this.$route.path !== '/' && this.$route.name !== 'Item'"
/>
<Footer />
</div>
</template>
<script>
import Navbar from "./components/Navbar";
//other imports...
import Modal from "./components/Modal";
export default {
name: "app",
components: {
Modal,
//other components
SideItems
}
};
</script>
Routes:路线:
const routes = [
{
name: "Home",
path: "/",
component: index,
meta: {
title: "Home" + appName,
}
},
{
name: "Signup",
path: "/signup",
component: signup,
meta: {
title: "Signup" + appName,
}
},
//other routes...
{
name: "Item",
path: "/item/:id",
component: item,
meta: {
title: "Item" + appName,
}
},
];
Modal.vue:模态的.vue:
<template>
<div class="modal" id="item-modal" @click="modalHide">
<div class="modal-item-image" @click="modalHide">
<img :src="getMainImage" @click="modalHide" />
</div>
</div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
computed: {
...mapGetters(["getMainImage"])
},
methods: {
modalHide() {
document.getElementById("item-modal").style.animation =
"opacity-out 0.4s cubic-bezier(0.215, 0.61, 0.355, 1) forwards";
document.getElementById("item-modal").style.pointerEvents = "none";
}
}
};
</script>
For some reason, having the component above the navbar in my layout was the cause.出于某种原因,在我的布局中将组件放在导航栏上方是原因。 No idea why.
不知道为什么。
I moved it beneath the navbar and set the margin-top to -140px and this fixed the issue.我将它移到导航栏下方并将 margin-top 设置为 -140px,这解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.