简体   繁体   English

导入组件时出现问题

[英]Issues importing components

I am trying to import the material design component "top app bar" but when I put the following code in: 我正在尝试导入材料设计组件“顶部应用栏”,但是当我将以下代码放入时:

import {MDCTopAppBar} from '@material/top-app-bar/mdc-top-app-bar';

I get the following error code: 我收到以下错误代码:

Uncaught TypeError: Failed to resolve module specifier "@material/top-app-bar/mdc-top-app-bar". 未捕获到的TypeError:无法解析模块说明符“ @ material / top-app-bar / mdc-top-app-bar”。 Relative references must start with either "/", "./", or "../". 相对引用必须以“ /”、“./”或“ ../”开头。

Any guidance on this would be appreciated. 任何对此的指导将不胜感激。 I am also very new to Polymer 3 coming from version 2 and am not used to using npm to install components and the new way of referencing so any resources on the topic that might be useful would be appreciated. 我也是来自版本2的Polymer 3的新手,并且不习惯使用npm来安装组件和新的引用方式,因此,对本主题中可能有用的任何资源都将不胜感激。

Thanks 谢谢

Change: 更改:

import {MDCTopAppBar} from '@material/top-app-bar/mdc-top-app-bar';

to

import {MDCTopAppBar} from '@material/top-app-bar/index';

And to import Style : 并导入Style

<style>
   @import "@material/top-app-bar/mdc-top-app-bar";
</style>

You can use require library, which doesn't need to mention path. 您可以使用require库,而无需提及路径。

Only the package name is sufficient. 仅软件包名称即可。

var MDCTopAppBar = require('@material');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM