vue组件eleme 时间选择器问题

来源:互联网 发布:苹果设计软件sketch 编辑:程序博客网 时间:2024/06/05 00:33

使用饿了么vue时间选择组件时选择的时间显示为本地时间  在传递数据到后台是时间慢8小时

解决方法.tostring();

或者定义date扩展

Date.prototype.Format = function (fmt) { //author: meizz     var o = {        "M+": this.getMonth() + 1, //月份         "d+": this.getDate(), //日         "h+": this.getHours(), //小时         "m+": this.getMinutes(), //分         "s+": this.getSeconds(), //秒         "q+": Math.floor((this.getMonth() + 3) / 3), //季度         "S": this.getMilliseconds() //毫秒     };    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));    for (var k in o)    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));    return fmt;}
再对时间进行格式化得到结果则为本地时区时间

另外可以对其模块化 新建dateFormat.js

export default function(fmt) {    var o = {        "M+": this.getMonth() + 1, //月份         "d+": this.getDate(), //日         "h+": this.getHours(), //小时         "m+": this.getMinutes(), //分         "s+": this.getSeconds(), //秒         "q+": Math.floor((this.getMonth() + 3) / 3), //季度         "S": this.getMilliseconds() //毫秒     };    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));    for (var k in o)    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));    return fmt;}
引入模块
import DateFormat from "../dateFormat.js"; //日期格式化扩展导入Date.prototype.Format = DateFormat; //日期格式化扩展加载

default关键字

别名的语法糖:

// d.jsexport default function() {}// 等效于:function a() {};export {a as default};

在import的时候,可以这样用:

import a from './d';// 等效于,或者说就是下面这种写法的简写,是同一个意思import {default as a} from './d';


原创粉丝点击