0

所以基本的入门工具包有一个变量'route'(显示当前页面的字符串),如果它是一个组件,我只需在 JSON 中的属性中添加一个 notify:true,它是 Polymer 的一部分(...) 称呼。

但是该示例没有将顶层包装在 Polymer(...) 中,那么如何将其设置为通知更改?

我可以将事件侦听器添加到#app 中,但它不会在不知道它必须发送的情况下发送该事件。

我想做的就是在当前页面发生变化时得到一个事件,所以我确定我只是忽略了一些非常明显的事情。

4

1 回答 1

1

您可以简单地创建一个绑定到顶级属性并触发事件的元素。

所以在你的 index.html 中:

<body ...>
<template is="dom-bind">
    <my-route-watcher route="{{route}}">
</template>
</body>

在你的 my-route-watcher.html 中:

<dom-module id="my-route-watcher">

<script>
Polymer({
   is: "my-route-watcher",

   properties: {
       route: {
           type: String,
           notify: true
       }
   }
   routeChanged: function() {
        this.fire('the-route-changed', { msg: "woohoo" });
   }
});

</script>
</dom-module>
于 2015-07-26T08:05:07.857 回答