Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Find a way to allow "@" in attribute?

未關閉
#235 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
38/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
javascript
領域
frontend

研究方向

從提供的 htm/preact 重現開始,檢查屬性如何傳遞到 setAttribute,尤其是 @click 的情況。將其行為與 x-on:click workaround 以及連結的 Alpine issues 進行比較;當 Alpine 的 @ 語法無需使用者重寫即可正常運作,並以該重現作為檢查依據時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

Both Vue and Alpine have this weird syntax where events get preceded by @. I'm using htm in a library for templating. Preact is more of an implementation detail, and not really exposed to users. I'm seeing someone who uses alpine on the rest of the page and wants an event handler that's handled by alpine in that template. Unfortunately the shorthand syntax doesn't seem to work due to setAttribute.

A reproduction is:

import { render } from "preact";
import { html } from "htm/preact";

// does work
render(
  html`
    <div x-data="{ open: false }">
      <button @click="open = !open">Expand</button>

      <span x-show="open">
        Content...
      </span>
    </div>
  `,
  document.body
);

(workaround is replacing @ to x-on:, but our user wasn't aware of this)

sandbox: https://codesandbox.io/s/festive-wildflower-qeugtn?file=/src/index.js

other relevant issues:
https://github.com/alpinejs/alpine/issues/1235
https://github.com/alpinejs/alpine/issues/396
https://github.com/algolia/instantsearch/issues/5435

I'm guessing no workaround will be possible as it's actually setAttribute throwing, but I wonder if you know something that would avoid users changing their expectations.

主要語言
JavaScript
星號
9k
分支
181
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

developit/htm 的其他 Issue

查看 developit/htm 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。