16: mint-ui移动端
1.1 mint-ui安装与介绍
官网:http://mint-ui.github.io/docs/#/zh-cn2/loadmore
1、安装与引用
// 安装Vue 2.0 npm install mint-ui -S
// 引入全部组件 import Vue from 'vue'; import Mint from 'mint-ui'; Vue.use(Mint);
1.2 Datetime Picker的用法
参考博客:https://blog.csdn.net/qq_35430000/article/details/82183079
<template> <div class="pickerDemo"> <div class="showTime"> <p class="timeDes">当前时间是:{{this.selectedValue}}</p> <div class="selectTime" @click="selectData">选择时间</div> </div> <!-- @touchmove.prevent 阻止默认事件,此方法可以在选择时间时阻止页面也跟着滚动。 --> <div class="pickerPop" @touchmove.prevent> <!-- 年月日时分选择 --> <mt-datetime-picker lockScroll="true" ref="datePicker" v-model="dateVal" class="myPicker" type="datetime" year-format="{value}" month-format="{value}" date-format="{value}" hour-format="{value}" minute-format="{value}" second-format="{value}" @confirm="dateConfirm()"> </mt-datetime-picker> </div> </div> </template> <script> import Vue from 'vue' import {formatDate} from '@/assets/js/util/formatdate.js' import {DatetimePicker } from 'mint-ui' Vue.component(DatetimePicker.name, DatetimePicker) export default { name: 'pickerDemo', data () { return { dateVal: '2019-04-17', // 默认是当前日期 selectedValue: '2019-04-17' } }, components: { }, methods: { //获取当前时间,格式YYYY-MM-DD getNowFormatDate(){ var date = new Date(); var seperator1 = "-"; var year = date.getFullYear(); var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = year + seperator1 + month + seperator1 + strDate; return currentdate; }, // 打开时间选择器 selectData () { // 如果已经选过日期,则再次打开时间选择器时,日期回显(不需要回显的话可以去掉 这个判断) if (this.selectedValue) { this.dateVal = this.selectedValue } else { this.dateVal = new Date() } this.$refs['datePicker'].open() }, // 时间选择器确定按钮,并把时间转换成我们需要的时间格式 dateConfirm () { this.selectedValue = formatDate(this.dateVal) } }, created () { var nowData = this.getNowFormatDate(); this.selectedValue = nowData; }, } </script> <style scoped> </style>
// 只有年月日 export function formatDate (secs) { var t = new Date(secs) var year = t.getFullYear() var month = t.getMonth() + 1 if (month < 10) { month = '0' + month } var date = t.getDate() if (date < 10) { date = '0' + date } var hour = t.getHours() if (hour < 10) { hour = '0' + hour } var minute = t.getMinutes() if (minute < 10) { minute = '0' + minute } var second = t.getSeconds() if (second < 10) { second = '0' + second } return year + '-' + month + '-' + date } // 年月日时分 export function formatDateMin (secs) { var t = new Date(secs) var year = t.getFullYear() var month = t.getMonth() + 1 if (month < 10) { month = '0' + month } var date = t.getDate() if (date < 10) { date = '0' + date } var hour = t.getHours() if (hour < 10) { hour = '0' + hour } var minute = t.getMinutes() if (minute < 10) { minute = '0' + minute } var second = t.getSeconds() if (second < 10) { second = '0' + second } return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second }
1111111
作者:学无止境
出处:https://www.cnblogs.com/xiaonq
生活不只是眼前的苟且,还有诗和远方。