【发布时间】:2018-03-31 09:16:25
【问题描述】:
当我尝试在登录页面中隐藏抽屉时,它会发生错误。我使用dom-if 隐藏菜单栏,根据它的syntax 我使用<template> 标签。但它发生错误。
聚合物代码
<!-- Drawer content -->
<template is="dom-if" if="[[_isLogin()]]">
<app-drawer id="drawer" slot="drawer" swipe-open="[[narrow]]">
<app-toolbar>Menu</app-toolbar>
<iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
<a name="homepage" href="[[rootPath]]homepage">Homepage</a>
<a name="profile" href="[[rootPath]]profile">Profile</a>
<a name="temp" href="[[rootPath]]temp">Temp</a>
</iron-selector>
</app-drawer>
</template>
脚本
_routePageChanged(page) {
if(this._isLogin()) {
// If no page was found in the route data, page will be an empty string.
// Default to 'homepage' in that case.
this.page = page || 'homepage';
// Close a non-persistent drawer when the page & route are changed.
if (!this.$.drawer.persistent) {
this.$.drawer.close();
}
} else {
this.page = 'login';
}
}
注意:_isLogin() 存在,它返回 true 或 false
【问题讨论】:
-
上述错误表示您的抽屉尚未渲染或 dom-if 条件不正确。所以,
this.$.dawer已经没有定义了。 -
但是登录后抽屉就来了。
标签: javascript polymer polymer-2.x drawer