Find a way to allow "@" in attribute?
- 主要语言
- JavaScript
- 星标
- 9k
- 派生
- 181
- PR 合并指标
- 30 天内没有已合并 PR
描述
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:
```js
import { render } from "preact";
import { html } from "htm/preact";
// does work
render(
html`
Expand
Content...
`,
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.
贡献指南
调研方向
从提供的 htm/preact 复现开始,检查属性如何传递到 setAttribute,尤其是 @click 的情况。将其行为与 x-on:click workaround 以及链接的 Alpine issues 进行比较;当 Alpine 的 @ 语法无需用户重写即可正常工作,并以该复现作为检查依据时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- frontend
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100