javascript - 如何在 Laravel 项目中为 VueJS 3 设置 compilerOptions.isCustomElement

标签 javascript laravel vue.js compiler-errors vuejs3

我正在 Laravel 项目中开发 VueJS 3,我正在使用一个 JS 文件,该文件为我提供了用于 Markdown 工具栏的元素。基本上,它是一组功能,为我提供了应用所选 Markdown 选项的按钮。一切正常,但我得到了我希望它们消失的那些控制台错误。
它们都类似于这个:

Failed to resolve component: md-linedivider
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. 
  at <Markdowntoolbar> 
  at <Article onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > > 
  at <BaseTransition mode="out-in" appear=false persisted=false  ... > 
  at <Transition enter-active-class="animate__animated animate__fadeInLeft" leave-active-class="animate__animated animate__bounceOutUp" mode="out-in" > 
  at <RouterView> 
  at <App> 
  at <Bodycomponent> 
  at <App>

这就是说 md-linedivider 元素应该通过 compilerOptions.isCustomElement 从组件解析中排除。我真的到处寻找解决方案,我只找到了this one但我的 laravel 项目中没有 vue.config.js 来应用它。我尝试在 webpack.mis.js 和 app.js 中执行此操作,但没有成功。
有人知道吗?

最佳答案

在你的 webpack.mix.js 中试试这个

mix.js('resources/assets/js/app.js', 'public/js').vue({
  options: {
    compilerOptions: {
      isCustomElement: (tag) => ['md-linedivider'].includes(tag),
    },
  },
});

更新 4.8.22 - 对于 Vite 项目:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => ['md-linedivider'].includes(tag),
        }
      }
    })
  ]
})

关于javascript - 如何在 Laravel 项目中为 VueJS 3 设置 compilerOptions.isCustomElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71601714/

相关文章:

Laravel 播种与 Eloquent\Builder 关系失败

php - Laravel - 无效参数编号 : parameter was not defined

php - 在 PHP-PhantomJS 中执行 PhantomJS 程序时出错

javascript - 如何检查 Vanilla Vue.js 中的密码匹配?

javascript - Chrome 自动填充应该将表单设置为有效

vue.js - nuxt 3 useFetch() 返回错误 fetch failed()

javascript - jQuery Mobile ListView ,将投票按钮添加到行元素

javascript - 我们可以在 sails 中的 Create() 回调之后/之前更改属性值吗?

JavaScript 或 jquery 加载器

Javascript 绑定(bind)对象文字方法不起作用