【14】vue.js — 自定義標籤

有心部落格發表於2017-09-07

自定義標籤

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="js/vue.js" ></script>
        <style>
            youxin {
                width: 100px;
                height: 100px;
                /*** 自定義標籤必須設定display: block ***/
                display: block;
            }
        </style>
    </head>
    <body>
        <div id="box">
            <youxin></youxin>
        </div>
    </body>
    <script>
        window.onload=function(){
            Vue.elementDirective('youxin',{
                bind: function(){
                    this.el.style.background = 'red';
                }
            })
            var vm = new Vue({
                el: '#box'
            });
        }
    </script>
</html>

vue自定義標籤

相關文章