Web applications 聚合物-未能实现简单元件
网络开发新手。 试着做一个简单的元件 index.htmlWeb applications 聚合物-未能实现简单元件,web-applications,polymer,Web Applications,Polymer,网络开发新手。 试着做一个简单的元件 index.html <!doctype html> <html> <head> <title>My Test</title> <script src="./components/platform/platform.js"></script> <link rel="import" href="my-element.html">
<!doctype html>
<html>
<head>
<title>My Test</title>
<script src="./components/platform/platform.js"></script>
<link rel="import" href="my-element.html">
<style>
div { width: 300px;}
my-element { font: bold 16px cursive;}
</style>
</head>
<body>
<div>
<my-element></my-element>
</div>
</body>
</html>
我的测试
div{宽度:300px;}
我的元素{font:bold 16px草书;}
my element.html
RTRTHDFGHFGHDFGHDGSDFASDFA
屏幕上什么也没发生。
通过chrome SDL检查,所有资源均已加载正常(200)
这是呈现后的页面源:
<!doctype html>
<html>
<head>
<title>My Test</title>
<!-- <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> -->
<script src="./components/platform/platform.js"></script>
<link rel="import" href="my-element.html">
<style>
div { width: 300px;}
my-element { font: bold 16px cursive;}
</style>
</head>
<body>
<div>
<my-element></my-element>
</div>
</body>
</html>
我的测试
div{宽度:300px;}
我的元素{font:bold 16px草书;}
我做错了什么?你需要改变两件事:
- 将
属性添加到元素中,因为它不包含JavaScript,也不向noscript
Polymer('my-element',{})注册组件代码>
- 在my-element.HTML中导入主聚合HTML文件:
<!doctype html>
<html>
<head>
<title>My Test</title>
<!-- <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> -->
<script src="./components/platform/platform.js"></script>
<link rel="import" href="my-element.html">
<style>
div { width: 300px;}
my-element { font: bold 16px cursive;}
</style>
</head>
<body>
<div>
<my-element></my-element>
</div>
</body>
</html>