【问题标题】:Where can I add 'moment.suppressDeprecationWarnings = true' when using Vue-Moment?使用 Vue-Moment 时在哪里可以添加“moment.suppressDeprecationWarnings = true”?
【发布时间】:2020-03-11 10:19:10
【问题描述】:

我正在使用通过 npm 安装的 vue-moment。我即将推出一个网站,我不能冒险更改日期的格式,因为整个网站都非常需要它,我不想破坏任何东西。

我已经看到我可以通过添加以下内容来关闭来自 moment.js 的警告:moment.suppressDeprecationWarnings = true

但是,由于我使用的是 vue-moment,我没有脚本文件来更改设置。我已经尝试将它添加到 app.js 以及正在使用时刻的组件中,但是我仍然收到警告:'弃用警告:提供的值不是可识别的 RFC2822 或 ISO 格式。'

有没有办法可以抑制 Vue.js 中的警告?

【问题讨论】:

    标签: javascript vue.js momentjs


    【解决方案1】:

    必须尽早完成,就在使用插件的那一刻:

    import vueMoment from 'vue-moment';
    
    Vue.use(vueMoment);
    Vue.moment.suppressDeprecationWarnings = true;
    

    【讨论】:

    • 在尝试您的解决方案时,我得到“无法设置属性 'suppressDeprecationWarnings' of undefined'”
    • 它应该可以工作,codesandbox.io/s/wizardly-euler-e88qc。我不知道在 Vue.use(vueMoment) 之后 Vue.moment 未定义的任何条件。使用调试器并确保 vueMoment 是插件对象。
    • 好的,我现在设法让它工作,与您的示例相比,我只是设置了不同的设置,但是在匹配您的示例之后它很好。感谢您的帮助!
    猜你喜欢
    • 2019-06-09
    • 2023-03-09
    • 2020-06-21
    • 1970-01-01
    • 2020-01-10
    • 2019-01-17
    • 2019-09-27
    • 2021-07-15
    • 2020-09-16
    相关资源
    最近更新 更多