中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

Vue中多個元素或組件的過渡-創(chuàng)新互聯(lián)

<!DOCTYPE?html>
<html>
<head>
????<title></title>
????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
????<link?rel="stylesheet"?type="text/css"?href="./animate.css">
????<script?src="./vue.js"></script>
????<!--?<script?src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>?-->
????<style>
????????.myfade-enter,?.v-leave-to?{
????????????opacity:?0;
????????}
????????.v-enter-active,?.v-leave-active?{
????????????transition:?opacity?1s;
????????}
????</style>
</head>
<body>
????<div?id="root">
????????<transition?name="myfade">
????????????<div?v-if="show">hello</div>
????????????<div?v-else>bye</div>
????????</transition>
????????<button?@click="handleClick">切換</button>
????</div>
????<script?type="text/javascript">
????????var?vm?=?new?Vue({
????????????el:?"#root",
????????????data:?{
????????????????show:?true
????????????},
????????????methods:?{
????????????????handleClick:?function()?{
????????????????????this.show?=?!this.show
????????????????}
????????????}
????????});
????</script>
</body>
</html>

(像上面這種加了style并不會實現(xiàn)漸變效果,因為vue默認(rèn)是會盡量復(fù)用dom,想要vue不復(fù)用dom,要給其加上不同的key值)

為紅橋等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及紅橋網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計、網(wǎng)站制作、紅橋網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

加上不同key值后,漸變效果有了:

<!DOCTYPE?html>
<html>
<head>
????<title></title>
????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
????<link?rel="stylesheet"?type="text/css"?href="./animate.css">
????<script?src="./vue.js"></script>
????<!--?<script?src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>?-->
????<style>
????????.myfade-enter,?.myfade-leave-to?{
????????????opacity:?0;
????????}
????????.myfade-enter-active,?.myfade-leave-active?{
????????????transition:?opacity?1s;
????????}
????</style>
</head>
<body>
????<div?id="root">
????????<transition?name="myfade">
????????????<div?v-if="show"?key="hello">hello</div>
????????????<div?v-else?key="bye">bye</div>
????????</transition>
????????<button?@click="handleClick">切換</button>
????</div>
????<script?type="text/javascript">
????????var?vm?=?new?Vue({
????????????el:?"#root",
????????????data:?{
????????????????show:?true
????????????},
????????????methods:?{
????????????????handleClick:?function()?{
????????????????????this.show?=?!this.show
????????????????}
????????????}
????????});
????</script>
</body>
</html>

如果想設(shè)置多個屬性之間的切換效果,可以用mode(mode="in-out":先顯示要顯示的再隱藏要隱藏的。mode="out-in":和前面的相反):

<!DOCTYPE?html>
<html>
<head>
????<title></title>
????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
????<link?rel="stylesheet"?type="text/css"?href="./animate.css">
????<script?src="./vue.js"></script>
????<!--?<script?src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>?-->
????<style>
????????.myfade-enter,?.myfade-leave-to?{
????????????opacity:?0;
????????}
????????.myfade-enter-active,?.myfade-leave-active?{
????????????transition:?opacity?1s;
????????}
????</style>
</head>
<body>
????<div?id="root">
????????<transition?name="myfade"?mode="out-in">
????????????<div?v-if="show"?key="hello">hello</div>
????????????<div?v-else?key="bye">bye</div>
????????</transition>
????????<button?@click="handleClick">切換</button>
????</div>
????<script?type="text/javascript">
????????var?vm?=?new?Vue({
????????????el:?"#root",
????????????data:?{
????????????????show:?true
????????????},
????????????methods:?{
????????????????handleClick:?function()?{
????????????????????this.show?=?!this.show
????????????????}
????????????}
????????});
????</script>
</body>
</html>

組件動畫也是可以的(不需要上面的不同值的key):

<!DOCTYPE?html>
<html>
<head>
????<title></title>
????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
????<link?rel="stylesheet"?type="text/css"?href="./animate.css">
????<script?src="./vue.js"></script>
????<!--?<script?src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>?-->
????<style>
????????.myfade-enter,?.myfade-leave-to?{
????????????opacity:?0;
????????}
????????.myfade-enter-active,?.myfade-leave-active?{
????????????transition:?opacity?1s;
????????}
????</style>
</head>
<body>
????<div?id="root">
????????<transition?name="myfade"?mode="out-in">
????????????<child1?v-if="show">hello</child1>
????????????<child2?v-else>bye</child2>
????????</transition>
????????<button?@click="handleClick">切換</button>
????</div>
????<script?type="text/javascript">
????????Vue.component("child1",?{
????????????template:?"<div>child1</div>"
????????});
????????Vue.component("child2",?{
????????????template:?"<div>child2</div>"
????????});
????????var?vm?=?new?Vue({
????????????el:?"#root",
????????????data:?{
????????????????show:?true
????????????},
????????????methods:?{
????????????????handleClick:?function()?{
????????????????????this.show?=?!this.show
????????????????}
????????????}
????????});
????</script>
</body>
</html>

動態(tài)組件的實現(xiàn)方法:

<!DOCTYPE?html>
<html>
<head>
????<title></title>
????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
????<link?rel="stylesheet"?type="text/css"?href="./animate.css">
????<script?src="./vue.js"></script>
????<!--?<script?src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>?-->
????<style>
????????.myfade-enter,?.myfade-leave-to?{
????????????opacity:?0;
????????}
????????.myfade-enter-active,?.myfade-leave-active?{
????????????transition:?opacity?1s;
????????}
????</style>
</head>
<body>
????<div?id="root">
????????<transition?name="myfade"?mode="out-in">
????????????//通過動態(tài)組件的方式實現(xiàn):
????????????<component?:is="type"></component>
????????</transition>
????????<button?@click="handleClick">切換</button>
????</div>
????<script?type="text/javascript">
????????Vue.component("child1",?{
????????????template:?"<div>child1</div>"
????????});
????????Vue.component("child2",?{
????????????template:?"<div>child2</div>"
????????});
????????var?vm?=?new?Vue({
????????????el:?"#root",
????????????data:?{
????????????????type:?"child1"
????????????},
????????????methods:?{
????????????????handleClick:?function()?{
????????????????????this.type?=?this.type?==?"child1"???"child2"?:?"child1"
????????????????}
????????????}
????????});
????</script>
</body>
</html>

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

文章題目:Vue中多個元素或組件的過渡-創(chuàng)新互聯(lián)
網(wǎng)頁網(wǎng)址:http://www.rwnh.cn/article44/copehe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、網(wǎng)站收錄、移動網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、網(wǎng)站營銷、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
临桂县| 嫩江县| 合江县| 张家港市| 资阳市| 磐石市| 东乌珠穆沁旗| 青龙| 绥德县| 高陵县| 荔浦县| 准格尔旗| 灯塔市| 伽师县| 青海省| 朝阳市| 浙江省| 双流县| 蓝山县| 永昌县| 铁力市| 陇川县| 四子王旗| 北海市| 博罗县| 肇东市| 从江县| 长沙市| 海淀区| 泰顺县| 安远县| 连南| 临邑县| 大关县| 青冈县| 布拖县| 静安区| 钟山县| 扶绥县| 奉化市| 常熟市|