0
我想通過單擊工具欄左上方的菜單按鈕來切換paper-drawer
。問題是我在控制檯中得到以下錯誤:聚合物2.0中的錯誤定義函數
http://jsbin.com/degifisici/1/edit?html,console,output"ReferenceError: _toggle is not defined at HTMLElement.onclick (http://null.jsbin.com/runner:1:1805)"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<base href="http://polygit.org/polymer+:master/components/">
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="polymer/polymer-element.html">
<link rel="import" href="app-layout/app-layout.html">
<link rel="import" href="iron-icons/iron-icons.html">
<link rel="import" href="iron-icon/iron-icon.html">
<link rel="import" href="paper-item/paper-icon-item.html">
<link rel="import" href="paper-icon-button/paper-icon-button.html">
</head>
<body>
<dom-module id="my-el">
<template>
<app-header reveals>
<app-toolbar>
<paper-icon-button icon="menu" onclick="_toggle"></paper-icon-button>
<div main-title>My app</div>
<paper-icon-button icon="delete"></paper-icon-button>
<paper-icon-button icon="search"></paper-icon-button>
<paper-icon-button icon="close"></paper-icon-button>
<paper-progress value="10" indeterminate bottom-item></paper-progress>
</app-toolbar>
</app-header>
<app-drawer id="drawer" swipe-open></app-drawer>
</template>
<script>
class MyEl extends Polymer.Element {
static get is() { return 'my-el' }
constructor() {
super();
}
ready() {
super.ready();
}
_toggle() {
var drawer = this.$.drawer;
drawer.toggle();
}
}
customElements.define(MyEl.is, MyEl);
</script>
</dom-module>
<my-el></my-el>
</body>
</html>
我相信你不需要「手勢......」導入與點擊。但是,最好使用on-tap而不是on-click,因爲on-tap也適用於觸摸設備(也支持鼠標點擊)。點按需要「手勢...」導入。 – grohjy