当使用自定义元素时,控制台会发出这样的警告:Failed to resolve component: swiper-slide If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
当然这也并不影响代码的运行,但是作为程序员,我们必须要严谨。那么我们应该如何去除这个警告呢?
只需要给vite.config.js文件添加一个配置:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
// my-custom-element 是我们自定义的元素
isCustomElement: (tag) => ['my-custom-element'].includes(tag)
}
}
})
]
})