Nuxt 粒子效果
透過 tsParticles 在您的 Nuxt 專案中運行輕量級、高度可客製化的粒子模擬。
功能
- 為 Nuxt 3 而建
- 預設延遲載入
- 內建完整、精簡和基本捆綁包,或
- 使用自訂捆綁包以獲得額外效能
- 全部只需一個元件!
快速設定
- 將
nuxt-particles
相依性加入您的專案
# Using pnpm
pnpm add -D nuxt-particles
# Using yarn
yarn add --dev nuxt-particles
# Using npm
npm install --save-dev nuxt-particles
- 將
nuxt-particles
加入nuxt.config.ts
的modules
區段
export default defineNuxtConfig({
modules: [
'nuxt-particles'
]
})
就這樣!您現在可以在應用程式中使用 <NuxtParticles> 元件了!✨
請閱讀文件以取得更多資訊,包括設定和最佳化選項。關於如何設定粒子本身的說明可在 tsparticles 的網站上找到。
範例
<template>
<NuxtParticles
id="tsparticles"
url="/path/to/particles.json"
@load="onLoad"
></NuxtParticles>
<!-- or -->
<NuxtParticles
id="tsparticles"
:options="options"
@load="onLoad"
></NuxtParticles>
</template>
<script setup lang="ts">
import type { Container } from '@tsparticles/engine'
const options = {
// See https://particles.js.org/docs/interfaces/tsParticles_Engine.Options_Interfaces_IOptions.IOptions.html
}
const onLoad = (container: Container) => {
// Do something with the container
container.pause()
setTimeout(() => container.play(), 2000)
}
</script>
開發
# Install dependencies
pnpm install
# Generate type stubs
pnpm run dev:prepare
# Develop with the playground
pnpm run dev
# Build the playground
pnpm run dev:build
# Run ESLint
pnpm run lint
# Release new version
pnpm run release