Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

Element UI 时间插件转化为UTC时间之后赋值,插件不能正常赋值?

<el-form-item >
      <el-date-picker  v-model="cashboxform.StartTime" type="datetime" placeholder="选择开始时间" style="width:100%" @change="dateFormat"></el-date-picker>
</el-form-item>

Element UI 原有的时间格式不符合需求。通过@chang属性。

dateFormat(val){
         console.log(val)
        var dateTimeFirst = [];
        var dateTimeEnd = [];

        dateTimeFirst = val.split(" ")[0].split("-");
        dateTimeEnd = val.split(" ")[1].split(":");
        
        console.log(dateTimeFirst[0])
        console.log(dateTimeFirst[1])
        console.log(dateTimeFirst[2])
        console.log(dateTimeEnd[0])
        console.log(dateTimeEnd[1])
        console.log(dateTimeEnd[2])

        var dateYear = dateTimeFirst[0];
        var dateMonth = dateTimeFirst[1];
        var dateDay = dateTimeFirst[2];
        var dateHour = dateTimeEnd[0];
        var dateMinute = dateTimeEnd[1];
        var dateSecond = dateTimeEnd[2];

        var dateUTC = Date.UTC(dateYear,dateMonth-1,dateDay,dateHour,dateMinute,dateSecond);
        this.cashboxform.StartTime = dateUTC;

     },  
     

运行这段代码之后不能正常赋值。表现就是页面卡死。通过console.log() 显示时间在不停的增加。我在没一段代码试了,this.cashboxform.StartTime = dateUTC;这段代码赋值时,就会出现。如何处理?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

这样处理时间,用filter

filters: {    //时间格式处理,格式化为YYYY-MM-DD
      Moment : function(value, formatString){
        formatString = formatString || 'YYYY-MM-DD';
        return moment(value).format(formatString);
      }
    },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...