el-select远程搜索在ios移动设备无法调用键盘、中文无效登问题

1、问题一:el-select远程搜索在ios移动设备无法调用键盘

解决:

1、给el-select设置ref

2、el-select添加

@hook:mounted="cancelReadOnly"
@visible-change="cancelReadOnly"

3、编写cancelReadOnly的代码逻辑

//解决ios手机无法调用键盘
    cancelReadOnly(onOff) {
      this.$nextTick(() => {
        if (!onOff) {
          // ios 手机有延迟问题
          setTimeout(() => {
            const { selectInfo } = this.$refs
            const input = selectInfo.$el.querySelector('.el-input__inner')
            input.removeAttribute('readonly')
          }, 200)
        }
      });
    },

2、问题二:el-select远程搜索在ios移动设备中文无效

解决:

1、需要使用el-select的ref,所以需要提前设置

2、代码如下:

 this.$nextTick(() => {
      // 解决IOS 输入中文,无法触发el-select remote-method方法
      const { selectInfo } = this.$refs;
      const input = selectInfo.$el.querySelector('.el-input__inner')
      //监听事件,查询下拉框
      input.addEventListener('compositionend', e =>{
        this.getIntervieweeList(e.target.value)
      });
    })

 3、主要代码展示

<el-select
  ref="selectInfo"
  @hook:mounted="cancelReadOnly"
  @visible-change="cancelReadOnly"
  @blur.native.capture="onblur"
  clearable
  filterable
  remote
  reserve-keyword
  :remote-method="getList"
  placeholder="请输入">
  </el-option>
</el-select>
    //解决ios手机无法调用键盘
    cancelReadOnly(onOff) {
      // if (onOff) { // 打开下拉框 显示可清空按钮
      //   this.showClose = true
      // }
      this.$nextTick(() => {
        if (!onOff) {
          // ios 手机有延迟问题
          setTimeout(() => {
            const { selectInfo } = this.$refs
            const input = selectInfo.$el.querySelector('.el-input__inner')
            input.removeAttribute('readonly')
          }, 200)
        }
      });
    },
mounted() {

this.$nextTick(() => {
      // 解决IOS 输入中文,无法触发el-select remote-method方法
      const { selectInfo } = this.$refs;
      const input = selectInfo.$el.querySelector('.el-input__inner')
      //监听事件,查询下拉框
      input.addEventListener('compositionend', e =>{
        this.getIntervieweeList(e.target.value)
      });
    })

}

<style scoped> /* 基础响应式 */ .filter-container { padding: 10px; } /* 移动端表单项优化 */ @media (max-width: 768px) { .el-form-item { margin-bottom: 15px; } .el-form-item__label { float: none; display: block; text-align: left; padding: 0 0 8px 0; } .el-form-item__content { margin-left: 0 !important; } .mobile-full-width { width: 100%; } /* 解决iOS Safari渲染问题 */ :deep(.el-select) { width: 100%; } } /* 对话框移动端适配 */ :deep(.el-dialog) { @media (max-width: 768px) { width: 90% !important; margin-top: 5vh !important; } } </style> <template> <div class="filter-container"> <el-form :model="searchForm"> <el-row :gutter="15"> <!-- 问卷标题搜索 --> <el-col :xs="24" :sm="12" :md="6"> <el-form-item label="问卷标题"> <el-input v-model="searchForm.dcWjTitle" placeholder="输入问卷标题" clearable /> </el-form-item> </el-col> <!-- 被测评人ID搜索 --> <el-col :xs="24" :sm="12" :md="6"> <el-form-item label="被测评人ID"> <el-input v-model="searchForm.dcid" placeholder="输入被测评人ID" clearable /> </el-form-item> </el-col> <!-- 部门选择 --> <el-col :xs="24" :sm="12" :md="6"> <el-form-item label="人员部门"> <el-select v-model="searchForm.dcDept" placeholder="选择部门" clearable > ... </el-select> </el-form-item> </el-col> <!-- 状态选择 --> <el-col :xs="24" :sm="12" :md="6"> <el-form-item label="提交状态"> <el-select v-model="searchForm.state" placeholder="选择状态" clearable > ... </el-select> </el-form-item> </el-col> <!-- 搜索按钮 --> <el-col :xs="24" :sm="24" :md="6"> <el-form-item> <el-button type="primary" @click="handleSearch" icon="el-icon-search" class="mobile-full-width" >搜索</el-button> </el-form-item> </el-col> </el-row> </el-form> </div> </template> <script> export default { data() { return { searchForm: { dcWjTitle: '', dcid: '', dcDept: '', state: '' }, rawData: [], // 原始数据 departments: [ // 部门选项 { label: '技术部', value: 'tech' }, { label: '市场部', value: 'market' } ] } }, computed: { // 过滤后的数据 filteredData() { return this.rawData.filter(item => (!this.searchForm.dcWjTitle || item.title.includes(this.searchForm.dcWjTitle)) && (!this.searchForm.dcid || item.dcid === this.searchForm.dcid) && (!this.searchForm.dcDept || item.dept === this.searchForm.dcDept) && (!this.searchForm.state || item.state === this.searchForm.state) ) } }, methods: { // 触发搜索 handleSearch() { this.fetchFilteredData() }, // 从后端获取数据 async fetchFilteredData() { try { const params = { title: this.searchForm.dcWjTitle, dcid: this.searchForm.dcid, dept: this.searchForm.dcDept, state: this.searchForm.state } // 调用后端API const { data } = await axios.get('http://172.26.26.43/dev-api/wjdc/wj/listTx?', { params }) this.rawData = data } catch (error) { console.error('获取数据失败', error) } } } } </script> 我在台式电脑上运行这个代码页面,问卷标题、被测评人ID、人员部门、提交状态都在一行,我想每个单独一行,这样输入框就不会被挤压显得很小
最新发布
07-15
<template> <!-- 顶部搜索区域 --> <div class="filter-container"> <el-form :inline="true" :model="searchForm"> <!-- 问卷标题搜索 --> <el-form-item label="问卷标题"> <el-input v-model="searchForm.dcWjTitle" placeholder="输入问卷标题" clearable /> </el-form-item> <!-- 被测评人ID搜索 --> <el-form-item label="被测评人ID"> <el-input v-model="searchForm.dcid" placeholder="输入被测评人ID" clearable /> </el-form-item> <!-- 部门选择 --> <el-form-item label="人员部门"> <el-select v-model="searchForm.dcDept" placeholder="选择部门" clearable > <el-option v-for="dept in departments" :key="dept.value" :label="dept.label" :value="dept.value" /> </el-select> </el-form-item> <!-- 状态选择 --> <el-form-item label="提交状态"> <el-select v-model="searchForm.state" placeholder="选择状态" clearable > <el-option label="已提交" value="1" /> <el-option label="未提交" value="0" /> </el-select> </el-form-item> <el-form-item> <el-button type="primary" @click="handleSearch" icon="el-icon-search" >搜索</el-button> </el-form-item> </el-form> </div> <!-- 数据表格 --> <el-table :data="filteredData"> <!-- 表格列定义 --> </el-table> </template> <script> export default { data() { return { searchForm: { dcWjTitle: '', dcid: '', dcDept: '', state: '' }, rawData: [], // 原始数据 departments: [ // 部门选项 { label: '技术部', value: 'tech' }, { label: '市场部', value: 'market' } ] } }, computed: { // 过滤后的数据 filteredData() { return this.rawData.filter(item => (!this.searchForm.dcWjTitle || item.title.includes(this.searchForm.dcWjTitle)) && (!this.searchForm.dcid || item.dcid === this.searchForm.dcid) && (!this.searchForm.dcDept || item.dept === this.searchForm.dcDept) && (!this.searchForm.state || item.state === this.searchForm.state) ) } }, methods: { // 触发搜索 handleSearch() { this.fetchFilteredData() }, // 从后端获取数据 async fetchFilteredData() { try { const params = { title: this.searchForm.dcWjTitle, dcid: this.searchForm.dcid, dept: this.searchForm.dcDept, state: this.searchForm.state } // 调用后端API(示例) const { data } = await axios.get('/api/questionnaires', { params }) this.rawData = data } catch (error) { console.error('获取数据失败', error) } } } } </script> 帮我优化一下布局,适用于移动端
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值