如何给vue 日期控件赋值

泪湿孤枕 提交于 2019-11-29 09:58:58

项目中需要用到日期时间插件,尝试用bootstrap、element的时间插件都各有各的报错,对于一个菜鸟来说真的是很痛苦啊。终于,最后用了layDate实现了需要的功能

最终效果:

 

使用步骤:

1.下载js包

http://www.layui.com/laydate/

2.将laydate文件夹放在根目录的static下

 

3.在index.html中引入

复制代码
 1 <!DOCTYPE html>
 2 <html>
 3   <head>
 4     <meta charset="utf-8">
 5     <meta name="viewport" content="width=device-width,initial-scale=1.0">
 6     <title>XXX</title>
 7     <script src="./static/laydate/laydate.js" type="text/javascript" charset="utf-8"></script>
 8   </head>
 9   <body>
10     <div id="app"></div>
11     <!-- built files will be auto injected -->
12   </body>
13 </html>
复制代码

4.定义时间日期组件

复制代码
<template>
  <div class="hello">
    <input type="text" placeholder="选择体检时间" id="orderTime" v-model="date">
  </div>
</template>

<script>
export default {
    name: "myTime",
    data() {
        return {
            date: ""// 存储选择的日期
        };
      },
      mounted() {
    // 使用:执行一个laydate实例
        laydate.render({
            elem: "#orderTime", // 指定元素
              type: "datetime", // 组件的类型:year,month,time···        format: 'yyyy-MM-dd HH:mm'// 设置显示格式
              done: value => { // 点击确认执行的回调函数,会把当前选择的时间传入进来
                // 把选择的时间赋值给先前定义好的变量,显示在页面
                this.date = value;
              }
        });
      }
};
</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>
复制代码

5.引用组件

<div class="">
    <label for="orderTime">体检日期:</label>
    <myTime />
</div>

 

http://market.szonline.net/amaz/9908.html
http://market.szonline.net/amaz/9907.html
http://market.szonline.net/amaz/9905.html
http://market.szonline.net/amaz/9904.html
http://market.szonline.net/amaz/9903.html
http://market.szonline.net/amaz/9901.html
http://market.szonline.net/amaz/9900.html
http://market.szonline.net/amaz/9899.html
http://market.szonline.net/amaz/9897.html
http://market.szonline.net/amaz/9896.html
http://market.szonline.net/amaz/9895.html
http://market.szonline.net/amaz/9893.html
http://market.szonline.net/amaz/9892.html
http://market.szonline.net/amaz/9891.html
http://market.szonline.net/amaz/9889.html
http://market.szonline.net/amaz/9888.html
http://market.szonline.net/amaz/9886.html
http://market.szonline.net/amaz/9885.html
http://market.szonline.net/amaz/9884.html
http://market.szonline.net/amaz/9882.html
http://market.szonline.net/amaz/9881.html
http://market.szonline.net/amaz/9880.html
http://market.szonline.net/amaz/9865.html
http://market.szonline.net/amaz/9864.html
http://market.szonline.net/amaz/9863.html
http://market.szonline.net/amaz/9862.html
http://market.szonline.net/amaz/9861.html
http://market.szonline.net/amaz/9860.html
http://market.szonline.net/amaz/9859.html
http://market.szonline.net/amaz/9858.html
http://market.szonline.net/amaz/9857.html
http://market.szonline.net/amaz/9856.html
http://market.szonline.net/amaz/9855.html
http://market.szonline.net/amaz/9854.html
http://market.szonline.net/amaz/9853.html
http://market.szonline.net/amaz/9852.html
http://market.szonline.net/amaz/9851.html
http://market.szonline.net/amaz/9850.html
http://market.szonline.net/amaz/9849.html
http://market.szonline.net/amaz/9848.html
http://market.szonline.net/amaz/9847.html
http://market.szonline.net/amaz/9846.html
http://market.szonline.net/amaz/9845.html
http://market.szonline.net/amaz/9844.html
http://market.szonline.net/amaz/9843.html
http://market.szonline.net/amaz/9842.html
http://market.szonline.net/amaz/9841.html
http://market.szonline.net/amaz/9840.html
http://market.szonline.net/amaz/9839.html
http://market.szonline.net/amaz/9838.html
http://market.szonline.net/amaz/9837.html
http://market.szonline.net/amaz/9836.html
http://market.szonline.net/amaz/9835.html
http://market.szonline.net/amaz/9834.html
http://market.szonline.net/amaz/9833.html
http://market.szonline.net/amaz/9832.html
http://market.szonline.net/amaz/9831.html
http://market.szonline.net/amaz/9830.html
http://market.szonline.net/amaz/9829.html
http://market.szonline.net/amaz/9828.html
http://market.szonline.net/amaz/9827.html
http://market.szonline.net/amaz/9826.html
http://market.szonline.net/amaz/9825.html
http://market.szonline.net/amaz/9824.html
http://market.szonline.net/amaz/9823.html
http://market.szonline.net/amaz/9822.html
http://market.szonline.net/amaz/9821.html
http://market.szonline.net/amaz/9820.html
http://market.szonline.net/amaz/9811.html
http://market.szonline.net/amaz/9810.html
http://market.szonline.net/amaz/9809.html
http://market.szonline.net/amaz/9808.html
http://market.szonline.net/amaz/9807.html
http://market.szonline.net/amaz/9806.html
http://market.szonline.net/amaz/9805.html
http://market.szonline.net/amaz/9804.html
http://market.szonline.net/amaz/9803.html
http://market.szonline.net/amaz/9802.html
http://market.szonline.net/amaz/9801.html
http://market.szonline.net/amaz/9800.html
http://market.szonline.net/amaz/9799.html
http://www.72177.com/htm/201909/12/4495975.htm
http://www.72177.com/htm/201909/12/4495974.htm
http://www.72177.com/htm/201909/12/4495973.htm
http://www.72177.com/htm/201909/12/4495972.htm
http://www.72177.com/htm/201909/12/4495971.htm
http://www.72177.com/htm/201909/12/4495970.htm
http://www.72177.com/htm/201909/12/4495957.htm
http://www.72177.com/htm/201909/12/4495956.htm
http://www.72177.com/htm/201909/12/4495953.htm
http://www.reversequeen.cn
http://www.zoenuu.cn
http://www.dunnuu.cn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!