vue中下拉框、输入框、日期处理

方法一:直接用监听来处理下拉、输入框、日期**(注意mounted中和监听日期时都会初始化列表,做法:去掉mounted中的列表初始化方法)**

    watch: {
    "query.name"(newName) {
      this.query.page = 1;
      if (newName !== null) {
        this.query.name = newName ? newName : null;
        this.render();
      }
    },
    **//下拉框选择    (newName中包含0或不包含0时都可以用)**
     "params.state": {
      handler(newName, oldName) {
         console.log(newName);
         this.params.page = 1;
        this.params.state = newName == "" && newName != "0" ? null : newName;
        if (newName != null) this.getData();
       },
      immediate: true,
     },
      **//日期选择**
    doubles: {
      handler(newVisible, oldVisible) {
        if (Array.isArray(newVisible)) {
          this.render();
        } else {
          this.doubles = [];
        }
      },
      immediate: true,
    },
  },

方法二:键盘输入回车刷新、日期/下拉选择通过change来更新数据

 <el-date-picker
                v-model="dateList"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="changeDate"
                style="width: 250px"
              >
              </el-date-picker>
 <el-input
                id="aaa"
                v-model="onSiteQuery.keyword"
                clearable
                placeholder="请输入巡检编号"
                style="width: 150px"
                @keyup.enter.native="getList"
              ></el-input>
 <el-form-item prop="stype">
            <el-select
              v-model="params.state"
              placeholder="请选择报建状态"
              clearable
              @change="changeS"
            >
              <el-option
                v-for="(item, index) in slist"
                :key="index"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
     </el-form-item>
    ...
 data() {
    return {
    dateList:[]
    }
 },
  watch: {
    "onSiteQuery.keyword"(val) {
      this.query.page = 1;
      this.onSiteQuery.keyword = val ? val : null;
      //这里仅处理清空数据时刷新列表
      if (val == "") this.getList();
    },
  },
    methods: {
    **//下拉框选择    (newName中包含0或不包含0时都可以用)**
     changeS(newName) {
        this.params.page = 1;
        this.params.state = newName == "" && newName != "0" ? null : newName;
        this.getData();
    },
    **//日期选择**
    changeDate(){
      if (this.dateList && this.dateList.length) {
             this.onSiteQuery.stime = this.dateList[0].getTime() / 1000;
             this.onSiteQuery.etime = parseInt(
             (this.dateList[1].getTime() + 24 * 60 * 60 * 1000 - 1) / 1000
              );
          } else {
              this.onSiteQuery.stime = null;
              this.onSiteQuery.etime = null;
         }
          this.getList()
    },
     //请求列表
     getList() {
       
     // 在此处请求数据
      }
    }
  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值