透過 100 多個訣竅學習 Nuxt!

nuxt-particles

使用 tsParticles 輕鬆將粒子動畫加入您的 Nuxt 專案

Nuxt 粒子效果

npm versionnpm downloadsLicenseNuxt

透過 tsParticles 在您的 Nuxt 專案中運行輕量級、高度可客製化的粒子模擬。

功能

  • 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