瀏覽代碼

Update README

Caleb Porzio 5 年之前
父節點
當前提交
312af78553
共有 1 個文件被更改,包括 4 次插入9 次删除
  1. 4 9
      README.md

+ 4 - 9
README.md

@@ -596,7 +596,7 @@ Notice that, because of [event bubbling](https://en.wikipedia.org/wiki/Event_bub
 **Example:**
 
 ```html
-<div>
+<div x-data>
     <span @custom-event="console.log($event.detail.foo)"></span>
     <button @click="$dispatch('custom-event', { foo: 'bar' })">
 <div>
@@ -611,15 +611,10 @@ You can also take advantage of the previous technique to make your components ta
 **Example:**
 
 ```html
-<div @foo-event.window="console.log($event.detail.foo)">
-    <button @click="$dispatch('bar-event', { bar: 'bar' })">
-    <!-- When clicked, will console.log "foo" -->
-</div>
+<div x-data @custom-event.window="console.log($event.detail)"></div>
 
-<div @bar-event.window="console.log($event.detail.bar)">
-    <button @click="$dispatch('foo-event', { foo: 'foo' })">
-    <!-- When clicked, will console.log "bar" -->
-</div>
+<button x-data @click="$dispatch('custom-event', 'Hello World!')">
+<!-- When clicked, will console.log "Hello World!". -->
 ```
 
 `$dispatch` is a shortcut for creating a `CustomEvent` and dispatching it using `.dispatchEvent()` internally. There are lots of good use cases for passing data around and between components using custom events. [Read here](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events) for more information on the underlying `CustomEvent` system in browsers.