Custom Elements Interop changes breaking
Overview
- BREAKING: Custom elements whitelisting is now performed during template compilation, and should be configured via compiler options instead of runtime config.
- BREAKING: Special prop usage is restricted to the reserved
<component>
tag only. - NEW: There is new
v-is
directive to support 2.x use cases whereis
was used on native elements to work around native HTML parsing restrictions.
In Vue 2.x, whitelisting tags as custom elements was done via Vue.config.ignoredElements
:
// This will make Vue ignore custom element defined outside of Vue
// (e.g., using the Web Components APIs)
Vue.config.ignoredElements = ['plastic-button']
In Vue 3.0, this check is performed during template compilation. To instruct the compiler to treat <plastic-button>
as a custom element:
If using on-the-fly template compilation, pass it via
app.config.isCustomElement
:It’s important to note the runtime config only affects runtime template compilation - it won’t affect pre-compiled templates.
The Custom Elements specification provides a way to use custom elements as Customized Built-in Element by adding the is
attribute to a built-in element:
<button is="plastic-button">Click Me!</button>
In 3.0, we are limiting Vue’s special treatment of the is
prop to the <component>
tag only.
When used on the reserved
<component>
tag, it will behave exactly the same as in 2.x;When used on plain elements, it will be passed to the
createElement
call as theis
option, and also rendered as a native attribute. This supports the usage of customized built-in elements.2.x behavior: renders the
plastic-button
component.3.x behavior: renders a native button by calling
document.createElement('button', { is: 'plastic-button' })
In Vue 2 we recommended working around with these restrictions by using the is
prop on a native tag:
<table>
<tr is="blog-post-row"></tr>
</table>
With the behavior change of is
, we introduce a new directive v-is
for working around these cases:
WARNING
v-is
functions like a dynamic 2.x :is
binding - so to render a component by its registered name, its value should be a JavaScript string literal:
<!-- Incorrect, nothing will be rendered -->
<tr v-is="blog-post-row"></tr>
<!-- Correct -->
<tr v-is="'blog-post-row'"></tr>
Replace
config.ignoredElements
with eithervue-loader
‘scompilerOptions
(with the build step) orapp.config.isCustomElement
(with on-the-fly template compilation)