zoukankan      html  css  js  c++  java
  • elementui弹框中input在弹框来回切换情况下保持自动聚焦

    <el-button
                      @click="handleAntiClick"
                      type="primary"
                      size="small"
                      >弹框
    </el-button>
     
    <el-dialog
                title="注射"
                :visible.sync="AntiDialogVisible"
                width="30%"
                class="schDialog"
                center
              >
                <div>
                  <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="护工工号">
                      <el-input
                        v-model="form.jobNum"
                        placeholder="请输入或者扫描工号"
                        autofocus
                        v-focus
                        clearable
                        style="250px;"
                        ref="inputNum"
                        @keyup.enter.native="handleAntiOk"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="注射时间">
                      <!-- <el-input v-model="form.rejTime"></el-input> -->
                      <el-date-picker
                        v-model="form.rejTime"
                        type="datetime"
                        placeholder="选择日期时间"
                        :clearable="false"
                      ></el-date-picker>
                      <i style="color:red;font-size:12px;">抗生素有效期为30分钟</i>
                    </el-form-item>
                  </el-form>
                </div>
                <span slot="footer" class="dialog-footer">
                  <el-button @click="AntiDialogVisible = false">取 消</el-button>
                  <el-button type="primary" @click="handleAntiOk">确 定</el-button>
                </span>
    </el-dialog>
     
    data(){
      return{    
        AntiDialogVisible: false,
            form: {
              jobNum: '',
              rejTime: new Date(2020, 2, 2, 2, 2, 2),
              apply_id: ''
            }
      }
    }
    // 自定义v-focus指令
    directives: {
        focus: {
          // 指令的定义
          inserted: (el) => {
            // 聚焦元素
            el.querySelector('input').focus()
            // el.focus()
          }
        }
      },
    // 使用witch进行监听,从而赋予状态
    watch: {
        AntiDialogVisible(newVal, oldVal) {
          // console.log(newVal)
          if (newVal === true) {
            this.$nextTick(() => {
              // 自动获取焦点 element组件autofocus失效
              this.$refs.inputNum.focus()
              this.$refs.inputNum.$el.querySelector('input').focus()
            })
          }
        }
      },
    methods:{
      handleAntiOk(){
        this.AntiDialogVisible = false
      }
    }
  • 相关阅读:
    一篇说为什么有些人穷,有人却可以致富的亲身经历的文章
    jquery的隐式类型转换
    git学习笔记02-创建一个仓库提交一个文件-原来就是这么简单
    git学习笔记01-git最基本的工作原理分布式
    git-github-svn你们都是个什么东东
    工作中遇到的问题,虽然很白痴但是你可能也会遇到-2016-10-24
    你只有非常努力,才会看起起来毫不费力!
    jQuery的.click,.bind,.unbind,.on,.off,.delegate,.undelegate
    jQuery里面的普通绑定事件和on委托事件
    Phantomjs 在cmd命令行显示中文乱码
  • 原文地址:https://www.cnblogs.com/ljygirl/p/12559772.html
Copyright © 2011-2022 走看看