2015-02-23 73 views
4

OK ..我已經配置Polymer Project,因爲它是在This Video無法運行一個簡單的應用聚合物

項目結構是:

enter image description here

我的自定義要素是:

<link rel="import" href="../bower_components/polymer/polymer.html"> 
<polymer-element name="hello-world" noscript> 
<template> 
    <h1>Hi From Custom Element</h1> 
</template> 
</polymer-element> 

index.html是:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Title of the document</title> 
<script type="text/javascript" src="bower_components/polymer/polymer.js"> 
</script> 
<link rel="import" href="elements/hello-world.html"> 
</head> 
<body> 
<hello-world></hello-world> 
</body> 
</html> 

OK。當我沒有服務器運行此代碼,我得到錯誤:

Imported resource from origin 'file://' has been blocked from loading by Cross-Origin Resource Sharing policy: Received an invalid response. Origin 'null' is therefore not allowed access. 

,當我在WAMP運行應用程序,我得到錯誤:

​​

polymer.js在這種情況下的任何幫助?

+1

'Polymer.js'是聚合物庫,使用Web組件,這是不需要爲了應用程序的工作。加載webcomponents.js這是Web組件的Polyfill。 – Adi 2015-02-23 09:26:12

回答

3

由於聚合物的性質,您不能只使用file: URI來運行。請參閱https://www.polymer-project.org/docs/start/reusableelements.html

在第二種情況下,請嘗試從bower_components/webcomponentsjs/webcomponents.js而不是bower_components/polymer/polymer.js加載腳本。

+1

只需改變一下,代碼就像魅力一樣。謝啦! – 2015-02-23 11:03:59