要在Nuxt中集成Fancybox,按照以下步骤:
安装依赖
# Usage with NPM
npm install --save @fancyapps/ui
# and with Yarn
yarn add @fancyapps/ui
项目新建plugins
目录,新建useFancybox.client.js
文件:
import { Fancybox } from "@fancyapps/ui";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide("Fancybox", Fancybox);
nuxtApp.$Fancybox.bind("[data-fancybox]", {
// Your custom options
});
});
将@fancyapps/ui/dist/fancybox/fancybox.css
增加到nuxt.config.ts
中:
export default defineNuxtConfig({
devtools: { enabled: false },
app: {
css: [
"@fancyapps/ui/dist/fancybox/fancybox.css",
],
}
})