vue 基础学习 第五天

2018-05-31  本文已影响55人  那就远走

41 css 动画

<!-- 1、引用 animate.css -->
<link rel="stylesheet" href="animate.css">

 <div id="app">
    <button @click="flag=!flag">切换</button>
    <!-- 2、用一个 <transition> 标签把动画影响的元素包裹起来 -->
    <!-- 3、给 <transition> 属性 enter-active-class="指定元素显示时的动画" leave-active-class="元素隐藏时的动画" -->
    <transition enter-active-class="animated fadeIn" leave-active-class="animated fadeOut">
        <h1 v-if="flag">测试</h1>
    </transition>
</div>

<script>
    var app = new Vue({
        el: '#app',
        data: {
            flag: true,
        },
    });
</script>
# enter="开始进入的样式"
# enter-active="进入过程中"
# enter-to="进完成后"
# leave-active="离开过程中"
# leave="完全离开后"

42 directive 自定义指令

<div id="app">
    <!-- <span v-star>测试</span> -->
    <input type="text" v-model="title" v-bindandupdate.focus="title">
</div>

<script>
    // Vue.directive('star', {
    //     // 绑定
    //     bind(el, bind) {
    //         console.log(bind);
    //     }
    // })
    // Vue.directive('test', {
    //     // 更新
    //     update(el, bind) {
    //         console.log(bind);
    //     }
    // })
    Vue.directive('bindandupdate', function(el, bind) {
        console.log(bind);
    })
    var app = new Vue({
        el: '#app',
        data: {
            title: "ceshi",
        },
    });
</script>

43 在组件中使用指令

<div id="app">
    <h1 v-test="color">字</h1>
    <input type="text" v-model="color" v-focus>
</div>

<script>
    var app = new Vue({
        el: '#app',
        data: {
            color: 'red',
        },
        directives: {
            // 这个相当于 bind() + update() 动作
            test(el, bind) {
                var color = bind.value ? bind.value : red;
                el.style.cssText = "color:" + color;
            },
            // 这个相当于其他动作
            focus: {
                // 比如 inserted : 当子元素插入到父元素的时候调用
                inserted(el, bind) {
                    el.focus();
                }
            }
        }
    });
</script>
上一篇下一篇

猜你喜欢

热点阅读