简体   繁体   English

vue3 isCustomElement 正在将组件检测为 vue 组件

[英]vue3 isCustomElement is detecting component as a vue component

I am trying to get a webcomponent working with vitejs.我正在尝试让一个 webcomponent 与 vitejs 一起工作。

component I am trying to use: https://www.webcomponents.org/element/input-knob我正在尝试使用的组件: https://www.webcomponents.org/element/input-knob

I did as describe in the docs.我按照文档中的描述做了。

install and setup @vitejs/plugin-vue安装和设置@vitejs/plugin-vue

https://github.com/vitejs/vite/tree/main/packages/plugin-vue#vitejsplugin-vue- https://github.com/vitejs/vite/tree/main/packages/plugin-vue#vitejsplugin-vue-

initiate the customelement in config.在配置中启动自定义元素。 ( I also tried simply putting the custom element in main.js https://github.com/vitejs/vite/issues/1312 (我也尝试简单地将自定义元素放在 main.js https://github.com/vitejs/vite/issues/1312

vite.config.js vite.config.js


import { VitePWA } from 'vite-plugin-pwa'
import vue from '@vitejs/plugin-vue'
export default {
  plugins: [
    VitePWA(),
    vue({
      template: {
        compilerOptions: {
          isCustomElement: tag => tag === 'input-knob'
        }
      }
    })
  ]
}



still getting the same warning:frowning:仍然收到相同的警告:皱眉:

app.config.isCustomElement = tag => tag.startsWith('input-')

console.log(app.config.isCustomElement('input-knob'))

main.js main.js


import { createApp } from 'vue'
import App from './App.vue'
import './index.css'

const app = createApp(App);

app.config.isCustomElement = tag => tag.startsWith('input-')

console.log(app.config.isCustomElement('input-knob'))
app.mount('#app')


[Vue warn]: Failed to resolve component: input-knob [Vue 警告]:无法解析组件:输入旋钮

the log returns true, so I am not sure where the problem actually is.日志返回 true,所以我不确定问题到底出在哪里。

Problem was vite version.问题是vite版本。 Pushing it to vite2 fixes this.将其推送到 vite2 可以解决此问题。

"vite": "^2.0.5"

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

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