聚合物示例代码在 Firefox 中不起作用

2024-04-14

我正在尝试 Google 提供的示例代码https://www.polymer-project.org/1.0/start/first-element/intro https://www.polymer-project.org/1.0/start/first-element/intro.

这是我到目前为止所拥有的:

索引.html:

<!DOCTYPE html>                                                                                                          
<html lang="en">                                                                                                         
  <head>                                                                                                                 
    <meta charset="utf8">                                                                                                
    <meta http-equiv="X-UA-Compatible" content="IE=edge">                                                                
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">              
    <script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.js"></script>                         
    <link href="/my_components/icon-toggle-demo.html" rel="import">                                                      
  </head>                                                                                                                
  <body>                                                                                                                 
    <icon-toggle-demo toggle-icon="star"></icon-toggle-demo>                                                             
  </body>                                                                                                                
</html>  

图标-切换-demo.html:

<link rel="import" href="https://polygit.org/components/polymer/polymer.html">                                              
<link rel="import" href="https://polygit.org/components/iron-icons/iron-icons.html">                                        
<link rel="import" href="icon-toggle.html">                                                                                 


<dom-module id="icon-toggle-demo">                                                                                          
  <template>                                                                                                                
    <style>                                                                                                                 
      :host {                                                                                                               
        font-family: sans-serif;                                                                                            
      };                                                                                                                    
    </style>                                                                                                                

    <h3>Statically-configured icon-toggles</h3>                                                                             

    <icon-toggle toggle-icon="star"></icon-toggle>                                                                          
    <icon-toggle toggle-icon="star" pressed></icon-toggle>                                                                  

    <h3>Data-bound icon-toggle</h3>                                                                                         

    <!-- use a computed binding to generate the message -->                                                                 
    <div><span>[[message(isFav)]]</span></div>                                                                              

    <!-- curly brackets ({{}}} allow two-way binding -->                                                                    
    <icon-toggle toggle-icon="favorite" pressed="{{isFav}}"></icon-toggle>                                                  
  </template>                                                                                                               

  <script>                                                                                                                  
    Polymer({                                                                                                               
      is: "icon-toggle-demo",                                                                                               
      message: function(fav) {                                                                                              
        if (fav) {                                                                                                          
          return "You really like me!";                                                                                     
        } else {                                                                                                            
          return "Do you like me?";                                                                                         
        }                                                                                                                   
      }                                                                                                                     
    });                                                                                                                     
  </script>                                                                                                                 
</dom-module> 

图标切换.html:

<link rel="import" href="https://polygit.org/components/polymer/polymer.html">                                              
<link rel="import" href="https://polygit.org/components/iron-icon/iron-icon.html">                                          

<dom-module id="icon-toggle">                                                                                               

  <template>                                                                                                                

    <style>                                                                                                                 
      /* local DOM styles go here */                                                                                        
      :host {                                                                                                               
        display: inline-block;                                                                                              
      }                                                                                                                     

      iron-icon {                                                                                                           
        fill: rgba(0,0,0,0);                                                                                                
        stroke: currentcolor;                                                                                               
      }                                                                                                                     
      :host([pressed]) iron-icon {                                                                                          
        fill: currentcolor;                                                                                                 
      }                                                                                                                     

    </style>                                                                                                                

    <!-- local DOM goes here -->                                                                                            
    <!-- <span>Not much here yet.</span> -->                                                                                
    <!-- <iron-icon icon="polymer"> -->                                                                                     
    <iron-icon icon="[[toggleIcon]]">                                                                                       
    </iron-icon>                                                                                                            
  </template>                                                                                                               

  <script>                                                                                                                  
  Polymer({                                                                                                                 
    is: 'icon-toggle',                                                                                                      
    properties: {                                                                                                           
      toggleIcon: String,                                                                                                   
      pressed: {                                                                                                            
        type: Boolean,                                                                                                      
        value: false,                                                                                                       
        notify: true,                                                                                                       
        reflectToAttribute: true                                                                                            
      }                                                                                                                     
    },
    listeners: {                                                                                                         
      'tap': 'toggle'                                                                                                    
    },                                                                                                                   
    toggle: function() {                                                                                                 
      this.pressed = !this.pressed;                                                                                      
    }                                                                                                                    
  });                                                                                                                    
  </script>                                                                                                              

</dom-module>  

该代码在 chrome 中运行良好,但在 FF 中出现以下错误:

TypeError: document.registerElement is not a function

我已经包含了polyfill。还缺少什么吗?


你没有做错什么。您的以下行index.html文件默认为 webcomponents polyfill 的最新版本 (v1.0.0-rc.1)。

<script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.js"></script>

Firefox 的当前版本似乎存在错误。在 Polymer 文档中链接的 Plunker 中也可以观察到相同的错误here https://plnkr.co/edit/QfsudzAPCbAu56Qpb7eB?p=preview。 Polymer 团队有望解决这个问题。

要暂时修复它,您可以显式使用旧版本。例如。

<script src="https://cdn.rawgit.com/webcomponents/webcomponentsjs/v0.7.24/webcomponents-lite.js"></script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

聚合物示例代码在 Firefox 中不起作用 的相关文章

随机推荐

  • 在 Hibernate 4 中创建会话工厂

    我在 Hibernate 4 中生成会话工厂时遇到问题 在 Hibernate 3 中我简单地做了 org hibernate cfg Configuration conf HibernateUtil getLimsInitializedC
  • 将函数应用于滚动窗口

    假设我有一个很长的清单A我想要计算的值 例如长度 1000 std100 对 即我想计算std A 1 100 std A 2 101 std A 3 102 std A 901 1000 在 Excel VBA 中 可以通过编写例如以下内
  • 如何对具有重复字符的字符串使用 substring 和 indexOf?

    我有以下内容String myString city Denver AND state Colorado 它有重复的 和 我如何检索州名 即科罗拉多州 我尝试了以下方法 String state myString substring myS
  • 如何从控制器运行 symfony 2 run 命令

    我想知道我怎样才能跑交响乐2来自浏览器查询或控制器的命令 这是因为我没有任何可能托管来运行它 并且每个 cron 作业都是由管理员设置的 我什至没有启用exec 因此 当我想测试它时 我必须将命令中的所有内容复制到某个测试控制器 这不是最佳
  • Hive Full Outer Join为相同的Join Key返回多行

    我正在对同一列上的 4 个表进行完全外连接 我想为连接列中的每个不同值仅生成 1 行 输入是 employee1 employee1 personid employee1 name 111 aaa 222 bbb 333 ccc
  • Android:本机线程与主线程同步

    在我的 android 应用程序中 我有一个从本机线程到 Java 代码的回调 需要与主 UI 线程同步 目的是 UI 线程根据从本机线程返回的信息显示选项列表 在用户选择一个选项之前 本机线程需要阻塞 用户选择一个选项后 本机线程读取该值
  • 基于 Q3DScatter 的自定义图表,QCustom3DItem 运行缓慢

    我想制作一个带条形的 3D 图表 条形颜色取决于其大小 两个都Qt 条形图和散点图类型 https doc qt io qt 5 qtdatavisualization overview html接近我正在寻找的东西 我最终创建了一个基于的
  • 将 .odt .doc .ods 文件转换为 .txt 文件

    我想转换所有 odt doc xls pdf文件到 txt files 我想使用 shell 脚本或 perl 脚本将这些文件转换为文本文件 有一个用于 odt 文件和类似文件的程序 odt2txt http packages debian
  • 带 GPU 的 Lightgbm 分类器

    model lgbm LGBMClassifier n estimators 1250 num leaves 128 learning rate 0 009 verbose 1 使用 LGBM 分类器 现在有没有办法通过 GPU 来使用它
  • 将社交登录(使用 Google 登录)添加到现有电子邮件/密码应用程序和数据库的最佳方法是什么?

    我想将谷歌登录集成到已有帐户注册和登录的应用程序中 我遵循了一些 YouTube 教程 现在我的前端可以通过 google 进行工作登录 成功登录后 它会返回一个 JWT 解码后 我会得到一个对象 其中包含电子邮件 姓名 pfp 和其他一些
  • C# 重写实例方法

    所以基本上我有一个对象 它接受实例并将它们添加到列表中 每个实例都使用虚拟方法 创建实例后我需要重写这些方法 我将如何覆盖实例的方法 你不能 您只能在定义类时重写方法 最好的选择是使用适当的Func委托作为占位符并允许调用者以这种方式提供实
  • 确定泛型函数调用了哪个函数

    我想知道如何快速找到特定对象的通用函数调用的特定函数 例子 library spatial data redwood K lt Kest redwood plot K 这不是一个普通的情节 这是一个为Kest 目的 因此 为了调查以找到所使
  • 定义引发异常的 lambda 表达式

    如何编写相当于以下内容的 lambda 表达式 def x raise Exception 以下行为是不允许的 y lambda raise Exception 给 Python 换肤的方法不止一种 y lambda for in thro
  • 在屏幕中间创建可滚动选项卡的最佳方法?

    当您使用个人资料时 Twitter 的移动应用程序在屏幕中间有一个可滚动的选项卡 当您单击屏幕中间的可滚动选项卡时 显示您的个人资料信息等的屏幕上半部分不会改变 推文和回复 媒体 等 我想知道如何创建这个 让一半的屏幕保持不变 然后有改变中
  • boost::uuids::random_generator 和多线程的唯一性

    当我使用单线程生成随机数时 生成的 4M uuid 中没有重复项 但如果我使用两个线程生成每个 1M 我会看到大约 16 20 个重复项 可能是什么原因 class TestUuid public std string GenerateUU
  • History.js 和标头重定向

    我在使用history js 时遇到问题 我不知道如何解决 在我正在开发的网站上 我们使用 History js 在页面之间移动 如果您单击任何链接 history js 就会通过 AJAX 加载 URL 更新 URL 并为内容创建过渡效果
  • gnuplot - 两个图的交集

    我在用gnuplot绘制来自两个单独的 csv 文件的数据 在此链接中找到 https drive google com open id 0B2Iv8dfU4fTUZGV6X1Bvb3c4TWs https drive google com
  • 未检测到 iOS 应用程序 URL

    我已经为我的 iOS 应用程序创建了一个自定义应用程序 URL URL 格式类似于 myappname texttobeparsed 当我将 URL 粘贴到 Safari 中时 我的应用程序会打开并正确处理该 URL 效果很好 问题是 iM
  • 如何理解Python中的i和-i? python 中的位操作

    我发现Python中的 表示基于位表达式的 与 运算 最近 我发现了一个非常聪明的代码 其中一行类似于 i i 其中 i 是一个整数 如何理解 i i 的结果 另外 python如何处理负整数 i 进行位操作 i i 清除所有位 1 但最后
  • 聚合物示例代码在 Firefox 中不起作用

    我正在尝试 Google 提供的示例代码https www polymer project org 1 0 start first element intro https www polymer project org 1 0 start