Element DateTimePicker日期時間選擇器的使用示例
組件—日期時間選擇器
日期和時間點

<template>
<div class="block">
<span class="demonstration">默認</span>
<el-date-picker
v-model="value1"
type="datetime"
placeholder="選擇日期時間">
</el-date-picker>
</div>
<div class="block">
<span class="demonstration">帶快捷選項</span>
<el-date-picker
v-model="value2"
type="datetime"
placeholder="選擇日期時間"
align="right"
:picker-options="pickerOptions">
</el-date-picker>
</div>
<div class="block">
<span class="demonstration">設(shè)置默認時間</span>
<el-date-picker
v-model="value3"
type="datetime"
placeholder="選擇日期時間"
default-time="12:00:00">
</el-date-picker>
</div>
</template>
<script>
export default {
data() {
return {
pickerOptions: {
shortcuts: [{
text: '今天',
onClick(picker) {
picker.$emit('pick', new Date());
}
}, {
text: '昨天',
onClick(picker) {
const date = new Date();
date.setTime(date.getTime() - 3600 * 1000 * 24);
picker.$emit('pick', date);
}
}, {
text: '一周前',
onClick(picker) {
const date = new Date();
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', date);
}
}]
},
value1: '',
value2: '',
value3: ''
};
}
};
</script>
日期和時間范圍

<template>
<div class="block">
<span class="demonstration">默認</span>
<el-date-picker
v-model="value1"
type="datetimerange"
range-separator="至"
start-placeholder="開始日期"
end-placeholder="結(jié)束日期">
</el-date-picker>
</div>
<div class="block">
<span class="demonstration">帶快捷選項</span>
<el-date-picker
v-model="value2"
type="datetimerange"
:picker-options="pickerOptions"
range-separator="至"
start-placeholder="開始日期"
end-placeholder="結(jié)束日期"
align="right">
</el-date-picker>
</div>
</template>
<script>
export default {
data() {
return {
pickerOptions: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一個月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三個月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}]
},
value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
value2: ''
};
}
};
</script>
默認的起始與結(jié)束時刻

<template>
<div class="block">
<span class="demonstration">起始日期時刻為 12:00:00</span>
<el-date-picker
v-model="value1"
type="datetimerange"
start-placeholder="開始日期"
end-placeholder="結(jié)束日期"
:default-time="['12:00:00']">
</el-date-picker>
</div>
<div class="block">
<span class="demonstration">起始日期時刻為 12:00:00,結(jié)束日期時刻為 08:00:00</span>
<el-date-picker
v-model="value2"
type="datetimerange"
align="right"
start-placeholder="開始日期"
end-placeholder="結(jié)束日期"
:default-time="['12:00:00', '08:00:00']">
</el-date-picker>
</div>
</template>
<script>
export default {
data() {
return {
value1: '',
value2: ''
};
}
};
</script>
Attributes



Picker Options

Shortcuts

Events

Methods

Slots

使用element UI的日期選擇器時,默認顯示當(dāng)天日期
需求:輸入框中要把當(dāng)天日期顯示在輸入框中,并且傳給后臺的日期格式是2019-06-12。(如交易數(shù)據(jù))

傳給后臺的時間格式為'2019-06-12'這樣的格式,,這個很好實現(xiàn),el-date-picker上添加value-format="yyyy-MM-dd"即可;
本來以為element UI中default-value設(shè)置之后,可以直接在輸入框中顯示,測試之后無用。最后通過下面的方法實現(xiàn)效果
<el-form-item label="交易數(shù)據(jù)">
<el-date-picker
type="date"
placeholder="選擇日期"
v-model="searchFormField.date"
style="width: 100%;"
value-format="yyyy-MM-dd"
></el-date-picker>
</el-form-item>
methods: {
getNowTime() {
var now = new Date();
var year = now.getFullYear(); //得到年份
var month = now.getMonth(); //得到月份
var date = now.getDate(); //得到日期
month = month + 1;
month = month.toString().padStart(2, "0");
date = date.toString().padStart(2, "0");
var defaultDate = `${year}-${month}-${date}`;
this.$set(this.searchFormField, "date", defaultDate);
},
}
到此這篇關(guān)于Element DateTimePicker日期時間選擇器的使用示例的文章就介紹到這了,更多相關(guān)Element DateTimePicker日期時間選擇器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
關(guān)于Elementui中toggleRowSelection()方法實現(xiàn)分頁切換時記錄之前選中的狀態(tài)
這篇文章主要介紹了關(guān)于Elementui中toggleRowSelection()方法實現(xiàn)分頁切換時記錄之前選中的狀態(tài),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
用vue實現(xiàn)注冊頁效果?vue實現(xiàn)短信驗證碼登錄
這篇文章主要為大家詳細介紹了用vue實現(xiàn)注冊頁,短信驗證碼登錄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11
mpvue實現(xiàn)左側(cè)導(dǎo)航與右側(cè)內(nèi)容的聯(lián)動
這篇文章主要為大家詳細介紹了mpvue實現(xiàn)左側(cè)導(dǎo)航與右側(cè)內(nèi)容的聯(lián)動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-10-10
vue+el-table點擊表頭實現(xiàn)改變其當(dāng)前樣式
這篇文章主要介紹了vue+el-table點擊表頭實現(xiàn)改變其當(dāng)前樣式問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08

