【问题标题】:Multiple Polymer Web Components Fail in FirefoxFirefox 中的多个 Polymer Web 组件失败
【发布时间】:2016-01-22 07:22:10
【问题描述】:

我已经使用多个自定义组件在 Chrome 中成功构建了一个网站,并且一切正常。

如果我在演示页面上一次运行一个组件,它会在 Firefox 上呈现。现在在使用多个自定义组件进行跨浏览器测试时,使用 Firefox v41 时它们都无法呈现*。 (虽然 1 次快速刷新会显示一些组件;侥幸?)

*我说的渲染失败的意思是页面上显示的dom中的内容,但似乎没有投影到shadow dom中,也没有继承自定义组件中定义的样式或功能,而只是从索引文件继承样式。

如何让多个 dom 模块在 Firefox 的一个页面上呈现?

错误日志:

Error: DuplicateDefinitionError: a type with name 'dom-module' is already registered
TypeError: Polymer.Base._getExtendedPrototype is not a function
TypeError: Polymer.CaseMap is undefined
TypeError: this._desugarBehaviors is not a function
TypeError: this._meta.byKey is not a function
TypeError: Polymer.Base._hostStack is undefined

索引文件:

<html>
<head>
    <link href='/css/styles.css' rel='stylesheet' type='text/css'>
    <script src="/bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
    <link rel="import" href="/bower_components/polymer/polymer.html">
    <link rel="import" href="/bower_components/ac-theme/color.html">
    <link rel="import" href="/bower_components/ac-theme/sizing.html">
    <link rel="import" href="/bower_components/ac-messagebar/ac-messagebar.html">
    <link rel="import" href="/bower_components/ac-site-footer/ac-site-footer.html">
</head>
<body>

<ac-messagebar>Message bar.</ac-messagebar>

    <ac-site-footer small-query="(max-width: 500px)">
        <section>
            <ul>
                <li>
                    Links<br/>
                    <ul>
                        <li><a href="#">Link 1</a></li>
                        <li><a href="#">Link 2</a></li>
                    </ul>
                </li>
            </ul>
        </section>
    </ac-site-footer>
</body>

自定义组件结构:

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../ac-theme/color.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-flex-layout/classes/iron-flex-layout.html">
<link rel="import" href="../iron-media-query/iron-media-query.html">

<dom-module id="ac-site-footer">
<template>
    <style is="custom-style">
        :host {
            /*css;*/
        }
</style>
    <iron-media-query
            id="mq"
            query="{{smallQuery}}"
            query-matches="{{smallScreen}}"
            on-query-matches-changed="_screenChanged"
            ></iron-media-query>
    <div class="content-container">
        <content></content>
    </div>        
</template>
<script>
    Polymer({
        is: "ac-site-footer",
        properties: {
            smallQuery: {
                type: String,
                value: '(max-width: 600px)',
                notify: true
            }
        },
        ...
</script>

【问题讨论】:

    标签: javascript firefox polymer web-component


    【解决方案1】:
    1. 将所有 link rel="import"... 从 index.html 移动到一个名为 elements.html(包括 polymer.html)的文件中。然后仅将 elements.html 导入到您的 index.html 文件中。

    2. 如果上述方法不起作用,请从您的 elements.html 文件中删除 import polymer.html,并确保所有 */ac-*/*.html 文件都包含针对 polymer.html 的导入语句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多