使用Polymer.dart使客户端应用程序正常工作需要哪些导入和脚本标记?
答案 0 :(得分:1)
<!DOCTYPE html>
<head>
<script src="packages/web_components/webcomponents-lite.min.js"></script>
<script src="packages/browser/dart.js"></script>
</head>
<body unresolved>
<my-element></my-element>
<script type="application/dart" src="index.dart"></script>
</body>
</html>
webcomponents-lite.min.js
脚本添加了Polymer polyfills。dart.js
才能在没有Dart VM的浏览器中运行。index.dart
包含您的自定义main();
并使用<my-element>
@HtmlImports(...)
index.dart
包含
import 'package:polymer/polymer.dart';
import 'my_element.dart';
/// Silence analyzer [MyElement]
main() async {
await initPolymer();
}
没有自定义主
使用<link rel="import" ...>
(不鼓励)
<!DOCTYPE html>
<head>
<script src="packages/web_components/webcomponents-lite.min.js"></script>
<link rel="import" href="my_element.html">
</head>
<body unresolved>
<my-element></my-element>
<script type="application/dart">export 'package:polymer/init.dart';</script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
或使用@HtmlImport(...)
导入元素
<!DOCTYPE html>
<head>
<script src="packages/web_components/webcomponents-lite.min.js"></script>
</head>
<body unresolved>
<my-element></my-element>
<script type="application/dart">
export 'package:polymer/init.dart';
import 'my_element.dart';
</script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
<强>提示:强> 如果没有明确的主脚本标记,则更难注册可反射变压器的入口点。可以使用生成文件的某些名称,但我还不知道这个文件名是什么。