日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

vant显示日期格式_Vue+Vant ui实现日期时间选择

發(fā)布時(shí)間:2023/12/15 vue 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vant显示日期格式_Vue+Vant ui实现日期时间选择 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Vue+Vant ui實(shí)現(xiàn)日期時(shí)間選擇

1、安裝Vant ui

npm i vant -S

2、在 main.js 中引入 Vant ui

// 引入vant

import Vant from 'vant'

import 'vant/lib/index.css'

Vue.use(Vant)

3、具體使用Vant DatetimePicker組件詳解

title="日期"

is-link

:value="timeValue"

@click="showPopup" />

v-model="currentDate"

type="datetime"

:loading="isLoadingShow"

:min-date="minDate"

:max-date="maxDate"

:formatter="formatter"

@cancel="show = false"

@confirm="confirmPicker"

/>

export default {

data() {

return {

timeValue: '',

show: false,

isLoadingShow: true,

currentDate: new Date(),

minDate: new Date(),

maxDate: new Date(2020, 12, 31),

};

},

created() {

this.getTime(); // 加載頁(yè)面顯示默認(rèn)時(shí)間

},

methods: {

// 顯示彈窗

showPopup () {

this.show = true

this.isLoadingShow = true

setTimeout(() => {

this.isLoadingShow = false

}, 500)

},

// 確認(rèn)選擇之后的時(shí)間

confirmPicker (val) {

let year = val.getFullYear()

let month = val.getMonth() + 1

let day = val.getDate()

let hour = val.getHours()

let minute = val.getMinutes()

// let second = val.getSeconds()

if (month >= 1 && month <= 9) { month = `0${month}` }

if (day >= 1 && day <= 9) { day = `0${day}` }

if (hour >= 0 && hour <= 9) { hour = `0${hour}` }

if (minute >= 0 && minute <= 9) { minute = `0${minute}` }

// if (second >= 0 && second <= 9) { second = `0${second}` }

this.timeValue = `${year}-${month}-${day} ${hour}:${minute}:00`

console.log(this.timeValue)

this.show = false

},

// 默認(rèn)顯示當(dāng)前時(shí)間

getTime () {

let date = new Date()

let y = date.getFullYear()

let m = date.getMonth() + 1

let d = date.getDate()

let h = date.getHours()

let min = date.getMinutes()

// let s = date.getSeconds()

if (m >= 1 && m <= 9) { m = `0${m}` }

if (d >= 1 && d <= 9) { d = `0$ozvdkddzhkzd` }

if (h >= 0 && h <= 9) { h = `0${h}` }

if (min >= 0 && min <= 9) { min = `0${min}` }

// if (s >= 0 && s <= 9) { min = `0${s}` }

let time = `${y}-${m}-$ozvdkddzhkzd ${h}:${min}:00`

this.timeValue = time

},

// 日期選項(xiàng)格式化函數(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}分`

} else if (type === 'second') {

return `${value}秒`

}

return value

},

}

}

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的vant显示日期格式_Vue+Vant ui实现日期时间选择的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。