[英]How to import moment.js in es6 file using having babel-loader.?
I am using vuejs framework and inside this we have created commonjs module to keep all the common code together.我正在使用 vuejs 框架,在其中我们创建了 commonjs 模块来将所有公共代码保存在一起。
This involves moment library as well.这也涉及矩库。 I tried importing it in below ways:我尝试通过以下方式导入它:
import moment from 'moment';
moment();
import * as moment from 'moment';
import moment from '../node_modules/moment/moment';
But it's giving error after building that但是在构建之后它给出了错误
Moment is not defined..
Thanks in advance 😊提前谢谢😊
您是否尝试过使用moment-es6包装器?
Did you try like this?你这样试过吗? I always use it like this then in vue.js我总是像这样在 vue.js 中使用它
Package I Use我使用的套餐
"moment": "^2.21.0",
/** * Moment * **/
window.moment = require('moment');
And vue pages和 vue 页面
data(){
return {
page_data: '',
moment: window.moment,
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.