vant時(shí)間控件使用方法詳解
本文實(shí)例為大家分享了vant時(shí)間控件的使用方法,供大家參考,具體內(nèi)容如下

代碼:
<template>
<div class="shoukuan">
<!-- 頭部公共搜索框 -->
<tabbar title="添加團(tuán)隊(duì)活動(dòng)"></tabbar>
<div class="con">
<van-cell-group>
<van-field v-model="name" clearable label="活動(dòng)名稱" placeholder="請(qǐng)選擇活動(dòng)名稱" />
<van-field v-model="starttime" clearable label="開(kāi)始時(shí)間" placeholder="請(qǐng)輸入開(kāi)始時(shí)間" @focus="start" />
<van-field v-model="endtime" clearable label="結(jié)束時(shí)間" placeholder="請(qǐng)輸入結(jié)束時(shí)間" @focus="end" />
</van-cell-group>
<van-cell-group>
<van-field
v-model="message"
rows="2"
autosize
label="活動(dòng)詳情"
type="textarea"
maxlength="50"
placeholder="請(qǐng)輸入"
show-word-limit
/>
</van-cell-group>
</div>
<van-button type="primary" size="large" @click="add">確認(rèn)添加</van-button>
<!-- 開(kāi)始時(shí)間控件 -->
<van-popup v-model="show" position="bottom">
<van-datetime-picker
v-model="currentDate"
type="datetime"
:min-date="minDate"
:max-date="maxDate"
@confirm="confirm"
@cancel="cancel"
:formatter="formatter"
/>
</van-popup>
<!-- 結(jié)束時(shí)間控件 -->
<van-popup v-model="show1" position="bottom">
<van-datetime-picker
v-model="currentDate1"
type="datetime"
:min-date="minDate"
:max-date="maxDate"
@confirm="confirm1"
@cancel="cancel1"
:formatter="formatter"
/>
</van-popup>
</div>
</template>
<script>
import tabbar from "../../components/navbar";
export default {
data() {
return {
name: "", //活動(dòng)名稱
message: "", //活動(dòng)詳情
show: false, //開(kāi)始時(shí)間彈窗
show1: false, //結(jié)束時(shí)間彈窗
minHour: 10,
maxHour: 20,
minDate: new Date(),
maxDate: new Date(2020, 11, 31),
currentDate: new Date(), //開(kāi)始標(biāo)準(zhǔn)時(shí)間
currentDate1: new Date(), //結(jié)束標(biāo)準(zhǔn)時(shí)間
starttime: "", //開(kāi)始時(shí)間
starttime1: "", //開(kāi)始時(shí)間時(shí)間戳
endtime: "", //結(jié)束時(shí)間
endtime1: "" //結(jié)束時(shí)間時(shí)間戳
};
},
components: {
tabbar
},
mounted() {},
methods: {
// 選擇開(kāi)始時(shí)間
start() {
this.show = true;
},
// 選擇結(jié)束時(shí)間
end() {
this.show1 = true;
},
// 點(diǎn)擊確定
confirm() {
this.show = false;
this.starttime =
this.currentDate.getFullYear() +
"年" +
(Number(this.currentDate.getMonth()) + 1) +
"月" +
this.currentDate.getDate() +
"日 " +
this.currentDate.getHours() +
":" +
this.currentDate.getMinutes();
this.starttime1 = new Date(this.currentDate).getTime() / 1000;
},
// 點(diǎn)擊取消
cancel() {
this.show = false;
},
confirm1() {
this.show1 = false;
this.endtime =
this.currentDate1.getFullYear() +
"年" +
(Number(this.currentDate1.getMonth()) + 1) +
"月" +
this.currentDate1.getDate() +
"日 " +
this.currentDate1.getHours() +
":" +
this.currentDate1.getMinutes();
this.endtime1 = new Date(this.currentDate1).getTime() / 1000;
},
cancel1() {
this.show1 = false;
},
// 處理控件顯示的時(shí)間格式
formatter(type, value) {
// 格式化選擇器日期
if (type === "year") {
return `${value}年`;
} else if (type === "month") {
return `${value}月`;
} else if (type === "day") {
return `${value}日`;
} else if (type === "hour") {
return `${value}時(shí)`;
} else if (type === "minute") {
return `${value}分`;
}
return value;
},
// 點(diǎn)擊添加按鈕
add() {
if (
!this.name.trim() ||
!this.starttime.trim() ||
!this.starttime.trim() ||
!this.message.trim()
) {
this.$toast("請(qǐng)輸入完整的活動(dòng)信息");
} else {
this.axios
.post("/api/agent_team/addTeamActivity", {
activity_name: this.name,
activity_content: this.message,
start_time: this.starttime1,
end_time: this.endtime1
})
.then(data => {
this.$toast("添加活動(dòng)成功");
setTimeout(() => {
this.$router.go(-1);
}, 1000);
});
}
}
}
};
</script>
<style lang="less" scoped>
.shoukuan {
padding-top: 44px;
.van-button--large {
width: 92%;
margin-left: 4%;
margin-top: 25%;
}
}
</style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue中子組件調(diào)用父組件的3種方法實(shí)例
vue子組件調(diào)用父組件的方法其實(shí)不難,最近整理了一下,下面這篇文章主要給大家介紹了關(guān)于Vue中子組件調(diào)用父組件的3種方法,需要的朋友可以參考下2022-05-05
在Vue3項(xiàng)目中使用Vuex進(jìn)行狀態(tài)管理的詳細(xì)教程
在?Vue?3?中使用?Vuex?進(jìn)行狀態(tài)管理是一個(gè)很好的實(shí)踐,特別是在涉及到多個(gè)組件間共享狀態(tài)的情況,下面是如何在?Vue?3?項(xiàng)目中設(shè)置和使用?Vuex?的教程,包括?state,?mutations,?actions,?getters?的概念及其用途,需要的朋友可以參考下2024-09-09
深入理解使用Vue實(shí)現(xiàn)Context-Menu的思考與總結(jié)
這篇文章主要介紹了使用Vue實(shí)現(xiàn)Context-Menu的思考與總結(jié),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-03-03
vue draggable resizable 實(shí)現(xiàn)可拖拽縮放的組件功能
這篇文章主要介紹了vue draggable resizable 實(shí)現(xiàn)可拖拽縮放的組件功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07
vue數(shù)據(jù)更新了但在頁(yè)面上沒(méi)有顯示出來(lái)的解決方法
有時(shí)候 vue 無(wú)法監(jiān)聽(tīng)到數(shù)據(jù)的變化,導(dǎo)致數(shù)據(jù)變化但是視圖沒(méi)有變化,也就是數(shù)據(jù)更新了,但在頁(yè)面上沒(méi)有顯示出來(lái),所以本文給出了三種解決方法,通過(guò)代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12
Vue-cli@3.0 插件系統(tǒng)簡(jiǎn)析
Vue-cli@3.0 是一個(gè)全新的 Vue 項(xiàng)目腳手架。這篇文章主要介紹了Vue-cli@3.0 插件系統(tǒng)簡(jiǎn)析,需要的朋友可以參考下2018-09-09
vue循環(huán)數(shù)組改變點(diǎn)擊文字的顏色
這篇文章主要為大家詳細(xì)介紹了vue循環(huán)數(shù)組改變點(diǎn)擊文字的顏色,非常實(shí)用的切換效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10

