首页 > 代码库 > vue 自定义指令directive

vue 自定义指令directive

 

 

            //自定义指令:directive 的传参——可以数据也可以是字符串
            Vue.directive(‘scroll‘, function (binding) {
                window.addEventListener(‘scroll‘, function () {
                    if (document.body.scrollTop + window.innerHeight >= document.body.clientHeight-20) {
                        var fnc = binding;
                        fnc();
                    }
                })
            });  

 

调用自定义指令:v-scroll="fn()"

<article class="library_list"  v-scroll="getMore">
        <a href="article_read.jsp?id={{value.id}}" target="_blank" v-for="value in myData.data">
            <dl class="border_bottom1_gray">
                <dt class="pic_box"><img :src="value.imgUrl" /></dt>
                <dd>
                    <p class="library_txt" v-cloak>{{value.title}}</p>
                    <p class="library_label"><span class="library_label_l " v-cloak>{{value.author}}&nbsp;&nbsp;{{value.ctime}}</span><span class="library_label_r" v-cloak>浏览量:{{value.pageView}}</span></p>
                </dd>
            </dl>
        </a>
        
        <!--<p class="nodata_hint" v-show="myData.length==0">暂无数据……</p>-->
        
    </article>

 

vue 自定义指令directive