29 Matching Annotations
  1. Mar 2023
    1. php artisan event:generate

      两种方法, 第一种,先在EventServiceProvider中把键值对配好,用 php artisan event:generate统一生成; 第二种,分别用artisan去生成event和listener,再去写键值对。

  2. Dec 2022
    1. As you can see, x-id accepts an array of ID names. Now any usages of $id() within that scope, will all use the same ID. Think of them as "id groups".

      x-id接收一个数组,该作用域下的所有$id会产生相同的id值,可以把x-id理解成一个id group

    1. Because of this difference in behavior, x-if should not be applied directly to the element, but instead to a <template> tag that encloses the element. This way, Alpine can keep a record of the element once it's removed from the page.

      一般使用在template上,不支持x-transition

    1. <template x-teleport="body" @click="open = false"> <div x-show="open"> Modal contents... (click to close) </div> </template>

      这部分点击后会被传送走,传送到x-data以外,脱离了alpine的实际控制区,但是点击外部的dom,还是会执行关闭动作。 首先,它阻止了x-data内组件的冒泡。 其次,它创建了一个事件的副本,并重新进行了派发。

    1. <div x-data="{ label: 'Hello' }" x-effect="console.log(label)"> <button @click="label += ' World!'">Change Message</button></div>

      监视器,组件属性值发生变化时运行。 1. 组件载入时运行一次; 2. 组件值发生变化时运行一次。

    1. <div @scroll.window.throttle="handleScroll">...</div>

      节流阀,laravel的登录页常常需要这个功能,防止恶意登录尝试,在限定的时间内,只能执行一次

    2. <div x-data @foo="alert('Button Was Clicked!')"> <button @click="$dispatch('foo')">...</button></div>

      对于自定义事件,必须加上@click="$dispatch('foo')"

    1. <div x-data="{ placeholder: 'Type here...' }"> <input type="text" x-bind:placeholder="placeholder"></div>

      设置placeholder

      <div x-data="{ placeholder: 'Type here...' }"> <input type="text" x-bind:placeholder="placeholder"> </div>
    1. Sometimes you may want to access the native browser event object inside your own code. To make this easy, Alpine automatically injects an $event magic variable:

      $event绑定本机浏览器事件对象 <button @click="$event.target.remove()">Remove Me</button>

    1. :class="{ 'hidden': ! open }"

      class类的存在与否取决于一个js变量,这是常常需要的功能,这里就有了x-bind的语法糖

      <div x-data="{ open: true }"> <span :class="{ 'hidden': ! open }">...</span> </div>