vue-seamless-scroll无缝滚动

1,118 阅读1分钟

官方文档

vue-seamless-scroll组件本身没有对copy的html做一个节点的深度事件复制(类似jq的clone(true))

解决方法: 事件代理,给父元素绑定对应事件,在需要的子元素上进行事件补获。

<vue-seamless-scroll :data="listData" :class-option="classOption" class="warp" @click.native="parentClick">
    ...
</vue-seamless-scroll>

<script>
	import vueSeamlessScroll from 'vue-seamless-scroll'
	
	export default {
            ...
            components: {
               vueSeamlessScroll
            },
            methods: {
               parentClick(e) {
                    console.log(e)
                    if (e.target.tagName == 'A') {      // 判断事件源是否是A标签
		     console.log(e.target.dataset.id)  // 这里获取点击节点的 data-id
                    }
		}
            }
	}
</script>