简体   繁体   English

非自定义元素中的 Polymer-on-tap 处理程序

[英]Polymer- on-tap handler in a non custom element

Using Polymer 1.2, I have使用聚合物 1.2,我有

<template is="dom-bind" id="app">
  <paper-tab name="portfolio" on-tap="bob">

This is in index.html, a non custom element.这是在 index.html 中,一个非自定义元素。

I have:我有:

  <script>
    function bob() {
      page('/portfolio');
    }
  </script>

but when I run it I get:但是当我运行它时,我得到:

`[dom-bind::_createEventHandler]: listener method `bob` not defined`

Since this is not a custom element, how do I assing the handler bob to on-tap ?由于这不是自定义元素,我如何将处理程序 bob 分配给on-tap

Here is a working example:这是一个工作示例:

<!doctype html>
<head>
    <script src="https://rawgit.com/webcomponents/webcomponentsjs/master/webcomponents-lite.js"></script>
    <base href="http://polygit.org/polymer/components/">
    <link href="polymer/polymer.html" rel="import">
    <link href="paper-button/paper-button.html" rel="import">
</head>
<body>

  <template is="dom-bind" id="app">
    <paper-button on-tap="bob">Click Me</paper-button>
  </template>
  <script>
    addEventListener('WebComponentsReady', function() {
      var t = document.querySelector("#app");
      t.bob = function() {
        console.log("Something Happenend");
      };
    });
  </script>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM