3***@qq.com
3***@qq.com
  • 发布:2025-02-10 14:47
  • 更新:2025-02-10 15:38
  • 阅读:20

vue3中input的selection-start和selection-end失效(app)

分类:HBuilderX

点击输入框选中输入框中的内容时,使用selection-start和selection-end失效

<template>  
    <view>  
        <view class="pickbox">  
            <view class="box" @click="pitch" v-if="selectShow"></view>  
            <input class="uni-input" type="digit" v-model="model" :focus="renameFocus" :style="style"  
             :selection-start="start" :selection-end="end" @blur="bindblur" @change="changeInput" :disabled="disabled" :placeholder="placeholder" :placeholder-class="placeholderClass"/>  
        </view>  
    </view>  
</template>  

<script setup>  
    import { ref ,onMounted, watch,nextTick } from 'vue';  
    import tools from "@/utils/tools.js"  
    const start = ref(-1)  
    const end = ref(-1)  
    const selectShow = ref(true);  
    const renameFocus = ref(false)  
    const model = defineModel()  
    const pro = defineProps({  
        type: {  
            type: [Number, String], // 1=数量 ,2=价格  
        },  
        placeholder:{  
            type: String,  
        },  
        placeholderClass:{  
            type: String,  
        },  
        style:{  
            type:[String,Object],  
        },  
        disabled: {  
            type:Boolean,  
            default: false, // 默认值  
        }  
    });  
    const emits = defineEmits(['bindblur','change'])  
    const pitch = () => {  
        renameFocus.value =true  
        selectShow.value = false  
        start.value =0  
        end.value = model.value.toString().length  
        // console.log('全选',start.value,end.value)  
    }  
    const bindblur = async() => {  
        renameFocus.value = false  
        selectShow.value = true  
        start.value = -1  
        end.value = -1  
        emits('bindblur',model.value)  
    }  
    const changeInput = () => {  
        emits('change',model.value)  
    }  
</script>
2025-02-10 14:47 负责人:无 分享
已邀请:
DCloud_UNI_yuhe

DCloud_UNI_yuhe

你好,使用selection-start和selection-end,是在自动聚焦的时候才会生效的

  • 3***@qq.com (作者)

    我这个就是自动聚焦呀,<view class="box" @click="pitch" v-if="selectShow"></view> 在input上面,点击的时候renameFocus=true自动聚焦,selectShow=false隐藏,然后选中输入框中的内容

    2025-02-10 17:22

要回复问题请先登录注册