从Webpack导入Vue应用后出现MomentJS警告

时间:2018-12-21 23:58:08

标签: javascript vue.js webpack momentjs

搜索了一会儿之后,我发现所有与该警告有关的帖子都是在使用MomentJS时引起的,但就我而言,此警告是在将其导入到main.js文件中之后显示的,甚至没有开始将其用于第一次,我什至还没有在代码的任何部分添加“ new Date()”或任何时刻调用。

这是我得到的整个警告:

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: 
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: function Vue (options) {
  if ("development" !== 'production' &&
    !(this instanceof Vue)
  ) {
    warn('Vue is a constructor and should be called with the `new` keyword');
  }
  this._init(options);
}, _f: undefined, _strict: undefined, _locale: [object Object]
Error
    at Function.eval [as createFromInputFallback] (webpack-internal:///./node_modules/moment/moment.js:320:98)
    at configFromInput (webpack-internal:///./node_modules/moment/moment.js:2606:19)
    at prepareConfig (webpack-internal:///./node_modules/moment/moment.js:2577:13)
    at createFromConfig (webpack-internal:///./node_modules/moment/moment.js:2544:44)
    at createLocalOrUTC (webpack-internal:///./node_modules/moment/moment.js:2631:16)
    at createLocal (webpack-internal:///./node_modules/moment/moment.js:2635:16)
    at hooks (webpack-internal:///./node_modules/moment/moment.js:12:29)
    at Function.Vue.use (webpack-internal:///./node_modules/vue/dist/vue.esm.js:4850:14)
    at eval (webpack-internal:///./src/main.js:51:46)
    at Object../src/main.js (http://localhost:8080/app.js:14037:1)

我在项目中添加momentJS的方式是运行:

npm i moment -D

然后在main.js中,我有以下内容:

import * as Moment from 'moment'

Vue.use(Moment)

window.app = new Vue({
    el: '#app',
    router: Router,
    store: store,
    render: h => h(App)
})

我知道这是一个警告,但每次刷新页面时都会令人讨厌。避免它会很好。

有任何线索吗?预先感谢。

1 个答案:

答案 0 :(得分:3)

您可能不想将use()传递给Vuemoment会将其视为插件(如here所述),并在传递moment作为参数的同时尝试调用它,当然use不会理解。这很可能是您收到该错误的原因。如果您想要Vue moment插件,请使用one here。如果您只想要.setStyle(Notification.BigPictureStyle(),则没有理由将其传递给NotificationCompat.Builder