鍍金池/ 問答/HTML/ 關(guān)于betterscroll上拉加載監(jiān)聽不到touchend事件

關(guān)于betterscroll上拉加載監(jiān)聽不到touchend事件

<template>
    
        <div class="wrapper" ref="wrapper">
            <div class="content">
                <div class="list" v-for="(item,index) in list" @click="ShowItem(item)">{{index}}</div>
            </div>            
        </div>
    
</template>
<script>
import BScroll from 'better-scroll'
    export default{
        data(){
            return{
                list:[1,2,3,4,5,6,7,1,8,9,10,11,12]
            }
        },
        mounted(){
            // this.$nextTick(() => {
                this.InitScroll()

              // })
        },
        methods:{
            InitScroll(){
                this.$nextTick(()=>{
                    if (!this.scroll) {
                        this.scroll=new BScroll(this.$refs.wrapper, {
                            click:true,
                            scrollY:true,
                            startY:0
                        })
                        this.scroll.on('touchend',(pos)=>{
                            console.log(pos)
                            if (pos.y>50) {
                                this.LoadData()
                            }
                        })
                        console.log(this.scroll)
                    }else{
                        this.scroll.refresh()
                    }
                })
                
            },
            ShowItem(item){
                console.log(item)
            },
            LoadData(){
                this.list.push(1,2,3)
            }
        }
    }
</script>
<style>
    .wrapper{
        height: 300px;
        overflow: hidden;
        border:1px solid #333;
    }
    .list{
        height: 50px;
        line-height: 50px;
        text-align: center;
    }
    
</style>

我這邊給this.scroll綁定了個touchend事件,然后希望監(jiān)聽到上拉事件,但是貌似監(jiān)聽不到,然后我再綁定touchend的事件后面console.log(this.scroll)查看了下屬性,它的touchendnull,說明沒有綁定上,但是我看別人的文章都是用on來綁定的呀,求指點

回答
編輯回答
黑與白

mmp我也是這個問題,原來是 那些狗日的亂寫參考文檔touchend 寫錯了,mmp啊,亂寫害死人

2017年11月13日 00:21
編輯回答
遲月

touchend寫錯了
是 this.scroll.on('touchEnd',(pos)
這種一般都是駝峰命名的
另外我估計你是要做上拉加載更多吧,這個是用pullingUp監(jiān)聽的,參考我另一個回答鏈接描述

2017年11月15日 13:47