Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue ignore custom component tag

On my site I am using Google CSE (custom search engine by google).

Here is my HTML:

<div id="app">
  ...
  <gcse:search></gcse:search>
  ...
</div>
<script type="text/javascript">
    new Vue({ el: '#app' })
</script>

As you can see, I have a "gcse input" placed inside of my vue application.

Therefore I am getting a warning:

[Vue warn]: Unknown custom element: <gcse:search>

So my question is how it possible to stop attempting to initialize this custom component in Vue.js?

Thanks in advance.

like image 717
abdulmanov.ilmir Avatar asked Jul 11 '17 17:07

abdulmanov.ilmir


3 Answers

Vue thinks that you are trying to load a Vue component named gcse:search.

In order to ignore this tag, add the v-pre directive:

<gcse:search v-pre></gcse:search>

Or, you could add the gcse:search tag to Vue's list of ignoredElements:

Vue.config.ignoredElements = ['gcse:search']
like image 160
thanksd Avatar answered Oct 20 '22 09:10

thanksd


In addition to the answer of thanksd, you can ignore the unknown tags by adding these tags in the ignoredElements property:

Vue.config.ignoredElements = ['gcse:search']

And you can also ignore these tags by using regex instead of using strings:

Vue.config.ignoredElements = [/gcse:*/]

This is very useful if you want to ignore more tags/components with a specific pattern. In this case, you could ignore all tags starting with "gcse"

like image 27
Miguel Gonzalez Avatar answered Oct 20 '22 08:10

Miguel Gonzalez


In Vue 3 it's different.

There are two ways to configure it.

1. If You are using runtime compiler

Note that this will not work if you are using runtime-only build

const app = createApp({})
app.config.compilerOptions.isCustomElement = tag => tag.startsWith('ion-')

2. Using runtime-only build

Here you have to add a rule in webpack.config.js for vue-loader

rules: [
  {
    test: /\.vue$/,
    use: 'vue-loader',
    options: {
      compilerOptions: {
        isCustomElement: tag => tag.startsWith('ion-')
      }
    }
  }
  // ...
]

Extra

if you are using laravel-mix the pervious ways will not work for you, the right way is to pass options in vue function of laravel-mix

mix.js('resources/js/app.js', 'public/js')
 .vue({
 options: {
  compilerOptions: {
   isCustomElement: tag => tag.startsWith('ion-')
  }
 }
})

References:

  1. https://v3-migration.vuejs.org/breaking-changes/global-api.html#config-ignoredelements-is-now-config-compileroptions-iscustomelement
  2. https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html#_2-x-syntax
  3. https://vue-loader.vuejs.org/guide/#manual-setup
like image 1
abublihi Avatar answered Oct 20 '22 10:10

abublihi