Polymer WebComponent中的Momentjs - 全局未定义

问题描述 投票:0回答:1

我想在web组件中使用momentjs来获得家庭助理中的自定义卡片

当我尝试导入库时,出现以下错误:

无法设置未定义的属性“时刻”

import './lib/moment.min.js';

class ContentCardExample extends HTMLElement {
    ...
}

知道发生了什么事吗?

polymer momentjs web-component
1个回答
2
投票

如果您从npm安装了片刻,则应将其导入为:

import moment from 'moment/src/moment.js';

并包括这样的任何语言环境(如果您需要它们:

import 'moment/src/locale/es.js';
© www.soinside.com 2019 - 2024. All rights reserved.