亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Vue中多個元素或組件的過渡

發布時間:2020-06-26 05:25:27 來源:網絡 閱讀:307 作者:梁十八 欄目:web開發
<!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并不會實現漸變效果,因為vue默認是會盡量復用dom,想要vue不復用dom,要給其加上不同的key值)

加上不同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>

如果想設置多個屬性之間的切換效果,可以用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>

動態組件的實現方法:

<!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">
????????????//通過動態組件的方式實現:
????????????<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>


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

高州市| 乌拉特后旗| 望城县| 镇沅| 团风县| 都匀市| 新野县| 塔城市| 桐乡市| 威信县| 安平县| 永修县| 锡林浩特市| 陕西省| 靖州| 龙江县| 成武县| 新蔡县| 防城港市| 新竹市| 巩留县| 汉源县| 琼结县| 荃湾区| 余庆县| 南岸区| 新野县| 西乌| 花垣县| 安国市| 汉阴县| 定陶县| 博湖县| 教育| 广水市| 玉龙| 沂源县| 庄浪县| 盐城市| 田阳县| 曲松县|