简体   繁体   English

vue 3 lottie-player 无法解析组件

[英]vue 3 lottie-player failed to resolve component

I am trying to use lottie-player in my vue 3 project but I always get the Warning that Vue failed to resolve the component lottie-player.我正在尝试在我的 vue 3 项目中使用 lottie-player,但我总是收到 Vue 无法解析组件 lottie-player 的警告。 I am following the official docs of lottieFiles ( https://lottiefiles.com/web-player ).我正在关注 lottieFiles ( https://lottiefiles.com/web-player ) 的官方文档。 The only browser that is not working is Chrome on iOS, for all other tested browsers and operating systems it only throws that warning but it works anyway.唯一不工作的浏览器是 iOS 上的 Chrome,对于所有其他经过测试的浏览器和操作系统,它只会抛出该警告,但它仍然可以工作。

I tried all kind of npm packages but i didn't find any working one for me.我尝试了所有类型的 npm 软件包,但没有找到适合我的软件包。 My latest idea is to try detecting chrome on iOS and show a different animation there.我的最新想法是尝试在 iOS 上检测 chrome,并在那里显示不同的 animation。 But of course it would be nice if anyone had a solution for my problem so that I don't get that warning.但当然,如果有人能解决我的问题,这样我就不会收到警告,那就太好了。 I mean it would suck if there is no propper way to use lottieFiles in Vue 3, right?我的意思是如果没有合适的方法在 Vue 3 中使用 lottieFiles 会很糟糕,对吧? lottie docs Vue warning lottie docs Vue警告

For anyone struggling with Vite2x+ change your vite.config.js file accordingly:对于任何在 Vite2x+ 上苦苦挣扎的人,请相应地更改您的 vite.config.js 文件:

import { fileURLToPath, URL } from 'url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue({
    template: {
      compilerOptions: { //✅ here
        isCustomElement: tag => tag === 'lottie-player'
      }
    }
  }) ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

As lottie-player is a Web Component you should declare it to compiler options.由于 lottie-player 是一个 Web 组件,您应该将其声明为编译器选项。

Check this Custom Elements Interop检查此自定义元素互操作

If you use vue-cli pass config through chainWebpack如果你使用 vue-cli pass config 通过 chainWebpack

check this Vue CLI config检查这个Vue CLI 配置

I'm currently updating the LottieFiles vue-lottie-player to work with Vue3 and as we wrap the lottie-web player, I was running in to this exact warning too!我目前正在更新 LottieFiles vue-lottie-player 以与 Vue3 一起使用,当我们包装 lottie-web 播放器时,我也遇到了这个确切的警告!

Managed to remove it by adding设法通过添加将其删除

isCustomElement: tag => tag === 'lottie-player'

inside my vue.config.js file.在我的 vue.config.js 文件中。 Heres the full config, you can ignore all the other things:这是完整的配置,您可以忽略所有其他内容:

//Compiler options
const path = require(`path`);

module.exports = {
    configureWebpack: {
        resolve: {
            symlinks: false,
            alias: {
                vue: path.resolve(`./node_modules/vue`)
            }
        }
    },
    chainWebpack: config => {
        config.resolve.alias.set('vue', '@vue/compat')

        config.module
            .rule('vue')
            .use('vue-loader')
            .tap(options => {
                return {
                    ...options,
                    compilerOptions: {
                        compatConfig: {
                            MODE: 2
                        },
                        isCustomElement: tag => tag === 'lottie-player'
                    }
                }
            })
    }
}

Link to the vue player: https://github.com/LottieFiles/lottie-vue vue播放器链接: https : //github.com/LottieFiles/lottie-vue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM