Nuxt Easy Lightbox
一個簡單的 Vue 3 圖片燈箱元件的插件,具有縮放/拖曳/旋轉/切換功能。
功能
- 🪶 輕量級,快速加載
- ❤️ 易於使用,功能豐富
- 🖼️ 燈箱中的圖片滑塊
快速設定
- 使用一個命令將模組安裝到您的 Nuxt 應用程式中
npx nuxi module add easy-lightbox
- 將模組新增至
nuxt.config.ts
export default defineNuxtConfig({ modules: ['nuxt-easy-lightbox'], })
- 接下來,在您想要使用燈箱的圖片元素旁邊使用元件
VueEasyLightbox
。<template> <div> <div v-for="(src, index) in imgs" :key="index" class="pic" @click="() => showImg(index)" > <img :src="src" /> </div> <VueEasyLightbox :visible="visibleRef" :imgs="imgs" :index="indexRef" @hide="onHide" /> </div> </template> <script setup> const visibleRef = ref(false); const indexRef = ref(0); const imgs = [ "https://via.placeholder.com/450.png/", "https://via.placeholder.com/300.png/", "https://via.placeholder.com/150.png/", { src: "https://via.placeholder.com/450.png/", title: "this is title" }, ]; const showImg = (index) => { indexRef.value = index; visibleRef.value = true; }; const onHide = () => (visibleRef.value = false); </script>
請記住
- 對於一組圖片,您只需要一個
VueEasyLightbox
,因為它們可以透過滑塊瀏覽。將所有圖片放入陣列並將其傳遞給imgs
參數。 - 對於單張圖片,每個
img
元素都需要個別的燈箱。
就是這樣!您現在可以在您的 Nuxt 應用程式中使用 Easy Lightbox 了✨
貢獻
本地開發
# Install dependencies
pnpm install
# Generate type stubs
pnpm dev:prepare
# Develop with the playground
pnpm dev
# Build the playground
pnpm dev:build
# Run ESLint
pnpm lint
# Run Vitest
pnpm test
pnpm test:watch
# Release new version
npm run release