我试图在Nuxt 3中使用flipbook-vue(带有tailwind css),但它不起作用. 不胜感激.

我在浏览器控制台中收到以下警告:

Failed to resolve component: Flipbook
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. 

组件本身没有显示在页面上,而是显示在html中:

<flipbook class="flipbook" pages="https://picsum.photos/200/300,https://picsum.photos/200/300,https://picsum.photos/200/300"></flipbook>

插件/flipbook.client.ts

import FlipBook from "flipbook-vue";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component("FlipBook", FlipBook);
});

pages/book.vue

<template>
  <section class="bg-cover">
    <div class="mx-12 my-8 p-4">
      <ClientOnly>
        <Flipbook
          class="flipbook"
          :pages="[
            'https://picsum.photos/200/300',
            'https://picsum.photos/200/300',
            'https://picsum.photos/200/300',
          ]"
        />
      </ClientOnly>
    </div>
  </section>
</template>

推荐答案

我不确定如何为该插件编写它,甚至不确定它是否是Nuxt或Flipbook问题.

我通过这个在当地实现了它

<script setup>
import Flipbook from 'flipbook-vue'
</script>

<template>
  <Flipbook class="flipbook" :pages="['https://source.unsplash.com/random/400x400?sig=1', 'https://source.unsplash.com/random/400x400?sig=2', 'https://source.unsplash.com/random/400x400?sig=3', 'https://source.unsplash.com/random/400x400?sig=4', 'https://source.unsplash.com/random/400x400?sig=5']" />
</template>

<style scoped>
.flipbook {
  width: auto;
  height: 500px;
}
</style>

That works fine in a component and not having that as a plugin is not too much of a big deal anyway.
Here is a Github comment that I posted, feel free to upvote and follow if you feel really concerned by that issue.

很抱歉没有进一步提供帮助,但我最近没有经常处理此类事情.我仍然认为通常的解决方案应该效果良好,但在这种情况下却并非如此.


编辑:这是一个带有Nuxt插件的工作解决方案!

我目前正在使用1.0.0-beta.4个.

所以,这应该是你的/plugins/flipbook.client.ts

import FlipBook from "flipbook-vue";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component("Flipbook", FlipBook);
});

这是您之后可以在页面中使用的内容

<template>
  <client-only>
    <Flipbook class="flipbook" :pages="['https://source.unsplash.com/random/400x400?sig=1', 'https://source.unsplash.com/random/400x400?sig=2', 'https://source.unsplash.com/random/400x400?sig=3', 'https://source.unsplash.com/random/400x400?sig=4', 'https://source.unsplash.com/random/400x400?sig=5']" />
  </client-only>
</template>

<style scoped>
.flipbook {
  width: auto;
  height: 500px;
}
</style>

工作良好,到目前为止没有任何错误.

enter image description here

Vue.js相关问答推荐

Vue路由路径匹配行为

是否可以将 nuxt3 与类星体框架一起使用

将媒体源/流绑定到视频元素 - Vue 3 组合 API

Nuxt3-Vue中的useRoute和useRouter有什么区别

Vuetify/Nuxt 生产环境组件在开发环境中无法正常工作

Vue 和 Nuxt 之间生命周期钩子的不同行为

是否可以让 html-webpack-plugin 从 css 生成