在vue中使用layDate日期时间插件

项目中需要用到日期时间插件,但是项目要使用公司内部的镜像源且没有UI库,只能放弃使用elementUI,iview等一些组件库,最后想到使用layDate实现该功能

参考:

https://www.cnblogs.com/duanzhenzhen/p/10611028.html
https://www.cnblogs.com/qq376324789/p/11224717.html

使用过程:

  1. 下载插件:https://www.layui.com/laydate/
  2. 复制文件夹到项目中
    在这里插入图片描述
    将laydate文件夹放在根目录的static下
  3. 引入
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>demo</title>
    <!-- 引入laydate -->
    <script src="./static/laydate/laydate.js" type="text/javascript" charset="utf-8"></script>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

在根目录的index.html文件中引入laydate.js

  1. 定义日期时间组件
<template>
  <div class="hello">
    <input type="text" readonly="readonly" placeholder="选择体检时间" id="orderTime" v-model="date">
  </div>
</template>

<script>
export default {
    name: "myTime",
    data() {
        return {
            date: ""// 存储选择的日期
        };
      },
    created:function(){                  
        setTimeout( function(){
            let that = this
            laydate.render({
                elem: "#orderTime", //指定元素
                type: 'datetime',
                format:'yyyy-MM-dd HH:mm:ss',
                trigger: 'click',
                done:function(value, date, endDate){
                    that.date=value;
                }
            });
        }, 0 );
    },
};
</script>

<style scoped>
.hello {
    display: inline-block;
}
.hello input {
    margin-left: -4px;
    width: 300px;
    height: 40px;
    border-radius: 4px;
    border: 1px solid #DCDFE6;
}
.layui-laydate .layui-this {
    background-color: #358ee7 !important;
}
</style>
  1. 引入组件
<template>
  <div class="">
    <label for="orderTime">日期时间:</label>
    <myTime />
  </div>
</template>

<script>
import myTime from './myTime.vue'
export default {
  name: 'HelloWorld',
  components:{
    myTime
  },
  data () {
    return {
      
    }
  }
}
</script>

<style scoped>

</style>

  1. 修改背景颜色和字体颜色
    修改laydate/theme/default/laydate.css,可以修改字体颜色和背景颜色
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

濮家大少

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值