vue控制滚动条滑动,平滑滑动smooth,隐藏滚动条

这是一个关于Vue.js组件的实现,名为ChosenTags,用于展示和管理已选择的标签。用户可以左右滑动查看标签,点击关闭图标删除特定标签。组件还提供了滚动功能,允许用户通过点击箭头来滚动标签列表。当标签被删除时,会同步更新父组件的数据并触发'closeTag'事件。
摘要由CSDN通过智能技术生成
<!--
 * @模块组件: 已选择的标签--初步组件
 * @Comp: <chosen-tags>
 * @desc: 已选择的标签,可左右滑动
 * @author: 叶良辰
 * @Date: 2022-06-17 17:01:17
 * @param: {Array} [tags: required] - 选中的标签数组
 * @example: 调用示例
 * <chosen-tags :tags.sync="tags"></chosen-tags>
 * @LastEditors: 叶良辰
 * @LastEditTime: 2022-06-20 14:07:51
-->
<template>
  <div class="search-chosed">
    <div class="copywriting">已选择:</div>
    <div ref="tagsCtn" class="tags-ctn">
      <el-tag ref="tags" v-for="(tag,index) in tags" size="mini" closable :key="tag.key" style="margin-left:10px" @close="closeTag(tag,index)">{{tag.label}}</el-tag>
    </div>
    <div v-if="showMoveIcon" class="move-icons">
      <i class="move-icon el-icon-arrow-left" style="margin-right:12px" @click="roll('left')"></i>
      <i class="move-icon el-icon-arrow-right" @click="roll('right')"></i>
    </div>
  </div>
</template>

<script>

export default {
  name:'ChosenTags',

  components:{},

  props:{
    showMoveIcon:{
      type:Boolean,
      default:true
    },
    tags:{
      type:Array,
      default:()=>[],
    }
  },

  data () {
     return {

     };
  },

  methods: {
    closeTag(tag,index){
      // 删除指定标签,按道理,对tags进行操作时,父组件的数据也同时改变了
      this.tags.splice(index,1)
      // 向父组件传出事件
      this.$emit('closeTag',this.tags)
    },
    roll(direction){
      console.log(direction,this.$refs.tagsCtn.scrollLeft);
      if(direction==='left'){
        console.log('向左');
        this.$refs.tagsCtn.scrollLeft -= 100
      }else{
        console.log('向右');
        this.$refs.tagsCtn.scrollLeft += 100
      }
    }
  },

  watch: {},

  filter: {},

  created() {},

  mounted() {},

  destroyed() {},

  // 路由钩子
}
</script>
<style lang='scss' scoped>
.search-chosed {
  position: relative;
  width: 100%;
  display: flex;
  font-size: 12px;
  margin-bottom: 24px;
  .copywriting {
    color: #666666;
    flex-shrink: 0;
    font-size: 12px;
  }
  .tags-ctn {
    display: flex;
    margin-right: 55px;
    overflow-y: hidden;
    overflow-x: auto;
    &::-webkit-scrollbar {
      display: none; /* Chrome Safari */
    }
    scroll-behavior: smooth;
  }
  .move-icons {
    position: absolute;
    right: 0;
    margin-right: 0;
    .move-icon {
      font-size: 14px;
      &:hover {
        cursor: pointer;
      }
    }
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值