Web Component
The same component is also available as a native custom element, wrapped with Vue's defineCustomElement. See Vue and Web Components in the Vue documentation for how Vue custom elements behave.
There are two entry points:
Automatic registration
Importing vue-vrm/wc-auto registers <vrm-canvas>:
Registering your own tag name
Import vue-vrm/wc and call register() with the tag name you want:
You can also define it yourself with the default export:
A constructor can only be defined once per custom element registry. Register a single tag name, and do not combine vue-vrm/wc with vue-vrm/wc-auto on the same page; defining a second tag name throws NotSupportedError.
vue-vrm/wc does not add anything to HTMLElementTagNameMap, so declare the type of your tag yourself:
Notes
- When using the element inside Vue templates, mark it as a custom element with
compilerOptions.isCustomElement(e.g.tag => tag === 'vrm-canvas'). - The canvas is rendered inside an open shadow root.
- The examples below use
<vrm-canvas>; replace it with your own tag name when usingvue-vrm/wc.
Setting props
- Primitive props (
string,boolean,number) can be set as attributes or as DOM properties. Attribute names are kebab-case (show-grid,aspect-ratio). ArrayBuffer, object, and array props (modelData,animationData,cameraInteraction,directionalLight, …) can only be set as DOM properties.
Prop defaults are applied when the element is connected to the document. Before that, reading a property such as element.width returns undefined.
Events
Vue emits are dispatched as native CustomEvents with the same names (model:loaded, animation:end, …). The emitted arguments are available as an array in event.detail.
Instance API
The instance API is exposed directly on the element: