vue中日期选择器一下选取2个数据,而后台传参数需要传2个开始时间和结束时间,所以可以使用watch监听器进行
<template>
<div>
<el-form ref="searchForm" :model="searchForm" label-width="100px">
<el-form-item label="文章状态:">
<el-radio v-model="searchForm.status" label>全部</el-radio>
<el-radio v-model="searchForm.status" :label="0">草稿</el-radio>
<el-radio v-model="searchForm.status" :label="1">待审核</el-radio>
<el-radio v-model="searchForm.status" :label="2">审核通过</el-radio>
<el-radio v-model="searchForm.status" :label="3">审核失败</el-radio>
</el-form-item>
<el-form-item label="频道列表:">
<el-select v-model="searchForm.channel_id" placeholder="请选择频道">
<el-option
v-for="item in channelList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-form-item>
<el-form-item label="时间选择:">
<el-date-picker
v-model="timetotime"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
></el-date-picker>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
name: "Article",
data() {
return {
timetotime: "",
searchForm: {
beginTime: "",
endTime: "",
status: "",
channel_id: ""
},
channelList:[],
};
},
watch: {
timetotime: function(newV) {
if (newV) {
this.searchForm.beginTime = newV[0];
this.searchForm.endTime = newV[1];
} else {
this.searchForm.beginTime = "";
this.searchForm.endTime = "";
}
}
},
created(){
this.getChannelList()
},
methods:{
getChannelList(){
let pro = this.$http({
url:"/mp/v1_0/channels",
methods:"get"
})
pro
.then(data =>{
this.channelList = data.data.channels
})
.catch(err =>{
return this.$message.error("或的频道失败:" + err)
})
}
}
};
</script>
<style lang="less" scoped>
</style>
效果如下图所示: