vue transition 在子組件中失效的解決
錯(cuò)誤代碼:
子組件:
<template>
<div v-show="showMine">
<div class="mask" @click.self="onMask"></div>
<transition name="slide-fade">
<div class="my_group" v-if="showMine">我的</div>
</transition>
</div>
</template>
<script>
export default {
name: "mine",
props: ["showMine"],
data() {
return {};
},
methods: {
onMask() {
this.$emit("onMask");
}
}
};
</script>
<style lang="less" scoped>
.mask {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.1);
z-index: 10;
}
.my_group {
width: 60%;
top: 0;
bottom: 0;
height: 100%;
background-color: #fff;
position: fixed;
z-index: 11;
}
.slide-fade-enter-active,
.slide-fade-leave-active {
transition: all 0.3s ease;
}
.slide-fade-enter,
.slide-fade-leave-to {
transform: translateX(-100%);
transition: all 0.3s ease;
}
</style>
父組件:
<template>
<div class="headers">
<div class="nav">
<div class="mine" @click="onMine">
<i class="cubeic-person"></i>
</div>
<div class="city">
深圳市
<i class="cubeic-pulldown"></i>
</div>
<div class="info">
<i class="cubeic-message"></i>
</div>
</div>
<app-mine :showMine="showMine" @onMask="onMask" />
</div>
</template>
<script>
import appMine from "../Mine";
export default {
name: "headers",
components: {
"app-mine": appMine
},
data() {
return {
showMine: false
};
},
methods: {
onMine() {
this.showMine = true;
},
onMask() {
this.showMine = false;
}
}
};
</script>
<style lang="less" scoped>
.nav {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 1.066667rem;
padding: 0 0.266667rem;
box-sizing: border-box;
font-size: 0.48rem;
.city {
font-size: 0.373333rem;
color: #7e7e7e;
}
}
.mine,
.info,
.city {
height: 100%;
line-height: 1.066667rem;
}
</style>
效果:

修改代碼只要把子組件中的的showMine放在mask元素中就可以

效果:

以上這篇vue transition 在子組件中失效的解決就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
從零開始搭建vue移動(dòng)端項(xiàng)目到上線的步驟
這篇文章主要介紹了從零開始搭建vue移動(dòng)端項(xiàng)目到上線的步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10
vue2前端調(diào)用WebSocket有消息進(jìn)行通知代碼示例
在Vue項(xiàng)目中實(shí)現(xiàn)全局的消息鏈接監(jiān)聽主要涉及到了WebSocket技術(shù),這是一種雙向通信協(xié)議,允許客戶端與服務(wù)器之間實(shí)時(shí)、高效地交換數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于vue2前端調(diào)用WebSocket有消息進(jìn)行通知的相關(guān)資料,需要的朋友可以參考下2024-07-07
淺談vue項(xiàng)目?jī)?yōu)化之頁(yè)面的按需加載(vue+webpack)
本篇文章主要介紹了vue項(xiàng)目?jī)?yōu)化之頁(yè)面的按需加載(vue+webpack),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12
vue2.x,vue3.x使用provide/inject注入的區(qū)別說(shuō)明
這篇文章主要介紹了vue2.x,vue3.x使用provide/inject注入的區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
使用vue init webpack項(xiàng)目名創(chuàng)建項(xiàng)目方式
這篇文章主要介紹了使用vue init webpack項(xiàng)目名創(chuàng)建項(xiàng)目方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
解決Vue+Electron下Vuex的Dispatch沒有效果問題
這篇文章主要介紹了Vue+Electron下Vuex的Dispatch沒有效果的解決方案 ,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05
在Vue使用$attrs實(shí)現(xiàn)構(gòu)建高級(jí)組件
本文我們主要來(lái)看下Vue3中的$attrs屬性。首先,我們會(huì)介紹它的用途以及它的實(shí)現(xiàn)與Vue2有哪些不兩同點(diǎn),并通過(guò)事例來(lái)加深對(duì)它的理解2022-09-09
vuex + axios 做登錄驗(yàn)證 并且保存登錄狀態(tài)的實(shí)例
今天小編就為大家分享一篇vuex + axios 做登錄驗(yàn)證 并且保存登錄狀態(tài)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09

