需求:elementui 标签页多个情况下,自带左右标签,当右标签滑动到最后一个的时候隐藏,左箭头同。
注意:查找实例会有时差,可以使用定时器延迟下。
isRightArrow(){
this.$nextTick(() => {
// 找出下面对应的nav实例
function findTabNavVue (vueStance) {
const childrens = vueStance.$children
const len = childrens.length
for (let i = 0; i < len; i ++ ) {
const child = childrens[i]
if (child.scrollNext) return child
}
}
const navVue = findTabNavVue(this.$refs.tabs)
if(navVue.$el.querySelector('.el-tabs__nav-prev')){
navVue.$el.querySelector('.el-tabs__nav-prev').style.visibility = 'hidden'
}
if (navVue.scrollable) {
let nextNode
let nextNode2
navVue.$watch('navOffset', function (currentOffset){
var navSize = this.$refs.nav['offsetWidth'];
var containerSize = this.$refs.navScroll['offsetWidth'];
const isRight = navSize - currentOffset <= containerSize
const isLeft = currentOffset == 0
nextNode = nextNode ? nextNode : navVue.$el.querySelector('.el-tabs__nav-next')
nextNode.style.visibility = isRight ? 'hidden' : ''
nextNode2 = nextNode2 ? nextNode2 : navVue.$el.querySelector('.el-tabs__nav-prev')
nextNode2.style.visibility = isLeft ? 'hidden' : ''
})
}
})
},
// 获取所有tab
this.tabDatas = res[6].data
if(this.tabDatas.lenght != 0){
setTimeout(() => {
this.isRightArrow()
}, 300);
}
版权声明:本文为qq_36533879原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。