<template>
<div>
<el-form ref="form" label-width="100px">
<el-form-item label="日期:" class="date_box">
<el-date-picker v-model="time" type="date" :clearable="true" format='yyyy-MM-dd' value-format='yyyy-MM-dd' prefix-icon="''" placeholder="请输入" @mouseover.native="setTimeIcon" @mouseleave.native="iconVisable=false">
</el-date-picker>
<i :class="['el-icon-date',iconVisable == false ?'data_icon':'data_display']"></i>
</el-form-item>
</el-form>
{{time}}
</div>
</template>
<script>
export default {
data () {
return {
time: '',
iconVisable: false,
}
},
mounted () {
},
methods: {
setTimeIcon () {
if (this.time == '' || this.time == null) {
this.iconVisable = false
}
this.iconVisable = true
},
}
}
</script>
<style lang="less" scoped>
.date_box {
position: relative;
width: fit-content;
}
.data_icon {
display: block;
position: absolute;
top: 50%;
right: 8px;
z-index: 9;
color: #c0c4cc;
font-size: 14px;
transform: translateY(-50%);
}
.data_display {
display: none;
}
</style>
或者图标写死
<template>
<div>
<el-form ref="form" label-width="100px">
<el-form-item label="日期:" class="date_box">
<el-date-picker v-model="time" type="date" :clearable="false" format='yyyy-MM-dd' value-format='yyyy-MM-dd' prefix-icon="''" placeholder="请输入">
</el-date-picker>
</el-form-item>
</el-form>
{{time}}
</div>
</template>
<script>
export default {
data () {
return {
time: ''
}
},
mounted () {
document.querySelector('.el-input__suffix').className += ' el-icon-date'
}
}
</script>
<style lang="less" scoped>
/deep/.el-icon-date {
right: 16px;
color: #c0c4cc;
font-size: 16px;
}
</style>