利用this.$refs给el-input等控件赋值

如果是el-input可以这样写:

<el-input ref="input1" v-model="queryForm.taskName" clearable></el-input>

利用refs赋值

this.$refs.input1.value ="22"

如果是自己封装的组件

 <el-form-item label="时间范围">
   <time-range ref="timeRange" :left-width="150" :right-width="150" @change="dateChange" />
 </el-form-item>

我的组件是由两个el-date-picker组成的

<template>
  <div class="time-range">
    <el-date-picker
      v-model="startTime"
      class="date"
      type="date"
      size="small"
      placeholder="选择日期"
      format="yyyy-MM-dd"
      value-format="yyyy-MM-dd"
      clearable
      :style="{width:leftWidth+'px'}"
      :picker-options="startOptions"
    />
    <span>&nbsp;&nbsp;</span>
    <el-date-picker
      v-model="endTime"
      class="date"
      type="date"
      size="small"
      placeholder="选择日期"
      format="yyyy-MM-dd"
      value-format="yyyy-MM-dd"
      clearable
      :style="{width:rightWidth+'px'}"
      :picker-options="endOptions"
    />
  </div>
</template>

利用refs给封装组件中的两个el-date-picker赋值

          const str = row.remindTime
          const str1 = str.split('到')[0]
          const str2 = str.split('到')[1]
          // 因为我的dateRange组件在打开对话框后才开始渲染,所以利用refs获取组件需要写在nexttikc中
          this.$nextTick(()=>{
            console.log('refffff:', this.$refs.timeRange)
            this.$refs.timeRange.$children[0].value = str1
            this.$refs.timeRange.$children[1].value = str2
          })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值