<html>
<head>
<title>core-icon-button</title>
<script src="../webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="core-icon-button.html">
<style>
</style>
</head>
<body unresolved>
<template is="auto-binding">
<template repeat="{{icon in $.meta.metaData.icons.iconNames}}">
<core-icon-button icon="{{icon}}" title="{{icon}}"></core-icon-button>
</template>
<core-icon-button icon="menu"><span>label</span></core-icon-button>
</div>
<core-iconset id="meta"></core-iconset>
</template>
</body>
</html>
请有人向我解释一下,为什么 core-iconset 元素可以在不“导入”的情况下使用? 抱歉我的英语不好。 非常感谢。
最佳答案
如果我们看一下 core-icon-button.html文件,在顶部我们找到以下两行:
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../core-icons/core-icons.html">
和core-icon依次导入core-iconset :
<link rel="import" href="../core-iconset/core-iconset.html">
因此 core-iconset.html 通过此导入链导入。
每个元素导入它需要的所有其他元素,这样元素的客户端不负责导入依赖项。由于这些导入(更准确地说:元素注册)是全局的(并且不限于导入元素),因此您可以在导入这些元素后在任何地方使用它们。
关于javascript - 为什么<core-iconset>可以在 polymer 中没有 "import"的情况下使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27728499/