透過 100+ 個技巧學習 Nuxt!

nuxt-particles

輕鬆地將粒子動畫新增到您的 Nuxt 專案,使用 tsParticles

Nuxt Particles

npm versionnpm downloadsLicenseNuxt

在您的 Nuxt 專案中使用 tsParticles 運行輕量級、高度可自訂的粒子模擬。

功能特色

  • Nuxt 3 而打造
  • 預設延遲載入
  • 內建完整、精簡和基本套件,或
  • 使用自訂套件以獲得額外效能
  • 全部僅需一個元件

快速設定

  1. nuxt-particles 依賴項新增至您的專案
# Using pnpm
pnpm add -D nuxt-particles

# Using yarn
yarn add --dev nuxt-particles

# Using npm
npm install --save-dev nuxt-particles
  1. nuxt-particles 新增至 nuxt.config.tsmodules 區段
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