Cynciya_ 2022-04-18 15:11 采纳率: 80%
浏览 57
已结题

vue.js 前端开发 动态组件切换

运行下面代码后,无法实现渐变切换是什么原因?
代码如下

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login</title>
    <script src="../js/vue.js"></script>
    <style>
        .page {
            width: 300px;
            height: 220px;
            border: 1px solid blue;
            padding-left: 15px;
        }

        .fade-enter,
        .fade-leave-to {
            opacity: 0;
        }

        .fade-enter-active,
        .fade-leave-active {
            transition: opacity 1s ease;
        }
    </style>
</head>

<body>
    <div id="app">
        <a href="#" @click="type = 'regist'">用户注册</a>
        <a href="#" @click="type = 'login'">用户登录</a>
        <transition mode="out-in">
            <component :is="type"></component>
        </transition>
    </div>

    <!-- 这是注册页面的模板 -->
    <template id="regist-template">
        <div class="page">
            <h4>注册页面</h4>
            <p>用户名:<input type="text"></p>
            <p>密码:<input type="password"></p>
            <p>二次密码:<input type="password"></p>
            <p><button>注册</button></p>
        </div>
    </template>

    <!-- 这是登录组件的模板 -->
    <template id="login-template">
        <div class="page">
            <h3>登录页面</h3>
            <p>用户名:<input type="text"></p>
            <p>密码:<input type="password"></p>
            <p><button>登录</button></p>
        </div>
    </template>
    <script>
        Vue.component('regist', {
            template: '#regist-template'
        })
        Vue.component('login', {
            template: '#login-template'
        })

        var vm = new Vue({
            el: "#app",
            data: {
                type: 'login'
            }
        })

    </script>
</body>

</html>

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-04-18 15:43
    关注

    img

    <transition mode="out-in">
    ==>
    
    <transition name="fade" mode="out-in">
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月18日
  • 已采纳回答 4月18日
  • 创建了问题 4月18日

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler