Tài liệu / Framework
Astro
Thêm các mục UI Loft vào website Astro. Astro cần thêm React và Tailwind trước, và một mục có chuyển động cần client directive.
- Phiên bản
- React
- Cần
- React + Tailwind 4 + shadcn
- Thời gian thiết lập
- Khoảng 5 phút
Thiết lập
Tạo website
Bỏ qua bước này nếu bạn đã có.
Terminalnpm create astro@latest my-site -- --template minimal --install --no-git --yes cd my-siteThêm React và Tailwind
Lệnh riêng của Astro cài cả hai và cập nhật
astro.config.mjs. Nó cũng tạosrc/styles/global.css.Terminalnpx astro add react tailwind --yesThêm alias @
Thêm
pathsdướicompilerOptionstrongtsconfig.json.tsconfig.json{ "compilerOptions": { "paths": { "@/*": ["./src/*"] } } }Thiết lập shadcn
Nó tạo
components.jsonvà điền theme vàosrc/styles/global.css.-ddùng các mặc định.Terminalnpx shadcn@latest init -dThêm một mục
Sao chép lệnh từ trang của bất kỳ mục nào. File sẽ nằm trong
src/components/.Terminalnpx shadcn@latest add https://uiloft.dev/r/glow-button.jsonDùng nó
Import styles một lần và import mục đó, rồi thêm
client:loadcho mục để nó chạy trong trình duyệt.src/pages/index.astro--- import "@/styles/global.css" import { GlowButton } from "@/components/glow-button" --- <html lang="en"> <body> <GlowButton client:load>Get started</GlowButton> </body> </html>
Nên biết
- Nếu không có client directive, Astro gửi mục dưới dạng HTML thuần: nó hiển thị, nhưng không chuyển động hay phản ứng.
client:visiblethay choclient:loadsẽ đợi đến khi mục cuộn vào tầm nhìn.- Nếu có layout, hãy import
@/styles/global.cssmột lần ở đó thay vì ở từng trang.