使用Polymer 1.2,我有
<template is="dom-bind" id="app">
<paper-tab name="portfolio" on-tap="bob">
这是在index.html中,非自定义元素。
我有:
<script>
function bob() {
page('/portfolio');
}
</script>
但是当我运行它时,我得到:
`[dom-bind::_createEventHandler]: listener method `bob` not defined`
由于这不是自定义元素,如何将处理程序bob赋予on-tap
?
答案 0 :(得分:1)
这是一个有效的例子:
<!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>