麻烦从 2019 年 10 月 25 日星期五 00:00:00 GM 到 2019-10-25 在 vue.js from method 中重新格式化日期值 [英] trouble reformat date value from Fri Oct 25 2019 00:00:00 GM to 2019-10-25 in vue.js from method

查看:27
本文介绍了麻烦从 2019 年 10 月 25 日星期五 00:00:00 GM 到 2019-10-25 在 vue.js from method 中重新格式化日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 vue.js 中获取正确格式的日期时遇到问题,这里是定义 prop 的方法

I have a problem getting the correctly formated date in vue.js here is the method that defines the prop

onDateClick({ date }) {
        this.showAddModal = true
        this.model.start = date
        this.model.end = date
      },

这是我得到错误返回格式的方法

and here is the method that I get the incorrectly returned format

save() {
      this.formData.append('name', this.model.name);
      this.formData.append('date', this.model.start);
      this.formData.append('description', this.model.description);
      for (var i = 0; i < this.model.files.length; i++) {
        const file = this.model.files[i];
        this.formData.append('files[' + i + ']', file);
      }

      window.axios.post(window.location.origin + '/calendar/store',
        this.formData,
        {
          headers: {
            'Content-Type': 'multipart/form-data',
          },
        })
        .then((response) => {
         location.reload();
        }).catch((err) => {
          console.log(err);
        });

我不知道在哪里重新格式化

I'm lost as to where to do the reformatting

推荐答案

使用 moment.js https://momentjs.com/

Use moment.js https://momentjs.com/

onDateClick({ date }) {
        let formattedDate = moment(date).format('YYYY-MM-DD')
        this.showAddModal = true
        this.model.start = formattedDate
        this.model.end = formattedDate
      },

这篇关于麻烦从 2019 年 10 月 25 日星期五 00:00:00 GM 到 2019-10-25 在 vue.js from method 中重新格式化日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆