vant-日期使用

摘要:
1、DatePicker.vue˂van-datetime-pickershow-postaltype="date":formatter="formatter":title="$attrs.label"@cancel="show=!

1、DatePicker.vue

<template>
    <div>
        <van-field
                v-model="result"v-bind="$attrs"readonly
                is-link
                @click="show = !show"
        />
        <van-popup v-model="show" position="bottom">
            <van-datetime-picker
                    show-postal
                    type="date"
                    :formatter="formatter"
                    :title="$attrs.label"@cancel="show = !show"@confirm="onConfirm"@change="changeFn"
            />
        </van-popup>
    </div>
</template>

<script>export default{
        model:{
            prop: "selectValue"},props:{
            columns:{
                type: Array},selectValue:{
                type: String}
        },data() {
            return{
                show: false,result: this.selectValue
            };
        },methods:{
            onConfirm(value) {
                this.result = this.timeFormat(value);
                this.show = !this.show;
            },timeFormat(time) { //时间格式化 2019-09-08
                let year = time.getFullYear();
                let month = time.getMonth() + 1;
                let day = time.getDate();
                return year + '-' + month + '-' +day;
            },
            //选项格式化函数
            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}时`
                } else if (type === 'minute') {
                    return`${value}分`
                } else if (type === 'second') {
                    return`${value}秒`
                }
                returnvalue
            },changeFn() { //值变化是触发
                // this.result = this.result
            },},watch:{
            selectValue: function(newVal) {
                this.result =newVal;
            },result(newVal) {
                this.$emit("input",newVal);
            }
        }
    };
</script>

<style></style>

2、父组件引用

 <date-picker
      :label="item.label"placeholder="请选择"v-model="dataList[item.name]"
      :required="item.mandatory"
      :rules="[{ required: item.mandatory, message: '请选择'+item.label}]"
/>

免责声明:文章转载自《vant-日期使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇oracle_多字段统计(多count)(转)每天一个linux命令(8):cp 命令,复制文件和文件夹下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

前端利器躬行记(7)——自制脚手架

path是Node.js中的路径模块path.resolve()用于解析绝对路径,__dirname可读取当前模块的目录名。静态资源最终路径=output.publicPath+加载器或插件的配置路径。假设html元素的背景是一条相对路径,那么最后生成的路径将会是“/img/lake.png”,其中配置的输出目录是“img”。paths.servedPath...

Java switch 枚举

Switch可以使用int.short、char、Enum和String其中,Enum是1.5之后的新特性,String是java8的新特性。所以正确的写作应该如下。...

wifi密码暴力破解

转自:Python最新暴力破解WiFi,攻破所有密码限制,最强破解!...

mysql状态查看 QPS/TPS/缓存命中率查看

showglobalstatusslike'Com_ commit';showstatslike“无缓冲池读取%”;Thread_cache_Hits=(1-Thread_created/connections)*100%(8)锁定状态mysql&gt;showstatslike“Binlog_缓存%”;...

PbootCMS后台增加轮播图自定义分组名称

我们知道,在PbootCMS后台的旋转木马图形模块中,当添加新的旋转木马图时,您不能自己选择组。相反,您可以自动创建组,例如组1、组2和组3。这显然对客户的体验不友好,而且您无法直观地知道在网页的哪个位置使用了旋转木马图。让我们分享一下如何启用PbootCMS后台来添加、删除和修改旋转木马图形组。...

C# winform开发嵌套Chrome内核浏览器(WebKit.net)开发(一)

//Www.cnblogs.com/Maxq/p/6566558.htmlWebKit.net是WebKit的一个net包。使用它,。net程序可以非常方便地集成和使用webkit作为加载网页的容器。EventArgse){WebKit.WebKitBrowser=newWebKitBrowser();this.Controls.Add(浏览器);...