如何将多个事件附加到一个活性元素

how to attach multiple events to a ractive element

文档 describing method call event handling 建议可以将多个处理程序附加到以逗号分隔的事件,如下所示:

<p on-click='speak(), bark()'>{{name}}</p>

然而,这会在元素首次呈现时引发错误,很明显我误解了文档。有人可以帮助我了解如何将多个处理程序附加到单击事件。

提前致谢

莱斯

我相信您仍在使用 0.7 或更早版本。更新到最新版本(撰写本文时为 0.8.7)和 you'll be able to do the following:

const Component = Ractive.extend({
  template: `
    <button on-click="@this.foo(), @this.bar()">Click Me</button>
  `,
  foo(){
    alert('Hello')
  },
  bar(){
    alert('World!')
  }
});

new Component({ el: 'body' });