首页 > 其他分享 >翻译语言选择自定义封装(elementUI)

翻译语言选择自定义封装(elementUI)

时间:2023-10-17 11:34:41浏览次数:30  
标签:自定义 title elementUI height 滚动条 item key 语言选择

基于elementUI下拉菜单项el-dropdown自定义封装

<template>
    <div>
        <el-dropdown trigger="click" @command="handleCommand">
            <el-input v-model="form.key1" suffix-icon="el-icon-arrow-down" placeholder="请选择"></el-input>
            <el-dropdown-menu slot="dropdown">
                <el-input v-model="form.key2" suffix-icon="el-icon-search" placeholder="搜索语言"></el-input>
                
                <div class="group-content">
                    <vue-scroll :ops="ops" ref="groupRef">
                        <div class="group-list">
                            <div v-for="item in languages" :key="item.title">
                                <div ref="titleRef">{{ item.title }}</div>
                                <el-dropdown-item
                                    v-for="(item, index) in 10"
                                    :key="`${index}+${item.title}`"
                                    class="sort-item"
                                    :command="index"
                                    >
                                    <span>中文</span>
                                </el-dropdown-item>
                            </div>
                        </div>
                    </vue-scroll>
                    <div class="key-list">
                        <div v-for="item in keyList" :key="item" @click="goIndex(item)">
                            {{ item }}
                        </div>
                    </div>
                </div>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
        
</template>
      
<script>

export default {
    data() {
        return {
            form:{
                key1:'',
                key2:''
            },
            keyList:['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'],
            languages:[
                {
                    title:'A',
                },
                {
                    title:'B',
                },
                {
                    title:'C',
                },
                {
                    title:'D',
                },
            ],
            //滚动条定义配置项
            ops: {
                vuescroll: {},
                scrollPanel: {
                    scrollingX: false,//关闭横向滚动
                },
                rail: {
                    keepShow: true,
                },
                bar: {
                    hoverStyle: true,
                    onlyShowBarOnScroll: false, //是否只有滚动的时候才显示滚动条
                    background: "#efefef", //滚动条颜色
                    opacity: 0.8, //滚动条透明度
                },
            },
        }
    },
    methods:{
        goIndex(key){
            const groupRef=this.$refs.groupRef.$children[0].$el
            const titleRef=this.$refs.titleRef
            titleRef.forEach(item=>{
                if(item.innerText===key){
                    groupRef.scrollTo({
                        top:item.offsetTop,
                        behavior:'smooth'
                    })
                }
            })
        },
        handleCommand(key){
            console.log(key)
            this.form.key1='中文'
        }
    }
}
</script>

<style scoped lang="scss">
/* 设置选项样式 */
/* 设置弹出框的宽高 */
/deep/ .el-dropdown-menu {
    width: 800px;
    // height: 400px;
    padding: 10px;
    .sort-item {
        display: inline-block;
        width: 100px;
        padding: 0 15px;
        margin: 10px 15px 2px 0;
        line-height: 32px;
        font-size: 14px;
        color: #333333;
        text-align: center;
        cursor: pointer;
    }
    .group-content{
        position: relative;
        height:420px;
        margin-top: 20px;
        .group-list{
            height: 400px;
            padding-right: 20px;
        }
        .key-list{
            position: absolute;
            right: 25px;
            top: 0;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            color: #999;
            div{
                text-align: center;
                cursor: pointer;
            }
        }
    }
}
</style>
      

实现效果:

标签:自定义,title,elementUI,height,滚动条,item,key,语言选择
From: https://www.cnblogs.com/772330747wh/p/17769280.html

相关文章

  • 自定义文档 Selection、Range 属性
    一document.execCommand现阶段项目中使用方法document.execCommand可直接操控选中文本,添加属性(操控文档)。但是由于fdocument.execCommand方法兼容性不好,浏览器之间的实现不一致,没有一个统一的标准。且自定义程度不高。官方已经将该方法移除。推荐使用Selection和Range......
  • vue自定义样式
    在项目中常常遇到一些页面由后台定制样式呈现,这就需要在页面中动态绑定style,如若定制样式里包含了伪类、媒体查询、hover效果能样式,寻常的v-bind:style内联样式可能就无法满足需求,这里就记录了一个解决办法。那么该如何操作呢,简单举个栗子:首先,我们在需要定制的样式元素上定义一......
  • Mybatis自定义TypeHandler完成字段加解密And枚举数据处理
    Mybatis自定义TypeHandler完成字段加解密And枚举数据处理新增And查询对枚举数据处理定义枚举@GetterpublicenumUserEnum{HOLD_A_POST("在职",10),RESIGN("离职",20);privateStringname;privateIntegervalue;UserEnum(Stringname,......
  • elementui组件封装(el-menu)
    废话不多说直接上代码:递归菜单项:<template><el-submenuv-if="menuData.children&&menuData.children.length>0":index="menuData.menuId"><templateslot="title"><iclass="el-icon-location......
  • 学习C语言心得-自定义函数-每调用一次函数 num的值+1
    每调用一次函数num的值+1#include<stdio.h>NUM(int*num){ (*num)++;}intmain(){ intnum=0; NUM(&num); printf("%d\n",num); NUM(&num); printf("%d\n",num); NUM(&num); printf("%d\n",num); NUM(&num)......
  • 学习C语言心得-自定义函数-对整形有序数组进行二分查找-二分法
    对整形有序数组进行二分查找#include<stdio.h>intfind(intarr[],intsz,intk){ intleft=0;intright=sz-1; while(left<=right) { intmid=left+right/2; if(k>arr[mid]) { left=mid+1; } if(k<arr[mid]) { right=mid......
  • 学习C语言心得-自定义函数 输入两个数字求和
    输入两个数字求和#include<stdio.h>intsum(inta,intb){ returna+b;}intmain(){ inta=0; intb=0; printf("请输入ab的值:"); scanf("%d%d",&a,&b); intSum=sum(a,b); printf("Sum=%d",Sum); return0;}运行......
  • 学习C语言心得-运用自定义函数求素数
    自定义函数求素数#include<stdio.h>intpanduan(inta){ inti=0; for(i=2;i<a;i++) { if(a%i==0) { returna; } } return0;}intmain(){ intnumber=0; printf("请输入一个数:"); scanf("%d",&number); int......
  • hive大数据测试(时间数据清洗UDF打包到hive中调用自定义函数,hive表数据导出到本机)
    1.数据清洗pom依赖:<properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding&......
  • iOS 17.1 Beta 3上线:iPhone 15 Pro自定义操作按钮误触问题修复了
    在iPhone15Pro和iPhone15ProMax上,苹果将静音拨片重新设计为自定义操作按钮,支持一键启用各种操作。在系统中选定你要用的快捷功能后,按住此操作按钮即可启动相应的操作,比如静音模式、专注模式、相机、手电筒、语音备忘录、翻译、放大器、快捷指令以及辅助功能等等。尽管操作......