To create a Vue 3 wrapper component in TypeScript, follow these steps:
MyWrapperComponent.ts. Make sure to include the .ts extension.defineComponent function.name property for the component object to give your wrapper component a name.props property as an object with all the props that will be passed to the wrapped component. You'll need to add the ...attrs spread operator to pass any extra attributes to the wrapped component.render function which returns a h function that creates and returns a new instance of the wrapped component. Pass in the props and attrs objects to the wrapped component instance.Here's how the final code for your wrapper component might look like:
index.ts394 chars23 linesIn this example, the MyWrapperComponent component is defined with two props: propA and propB. The render function creates a new instance of the WrappedComponent component and passes in all the MyWrapperComponent's props and attrs.
Make sure to change the ./WrappedComponent.vue import statement to the path of your own wrapped component.
gistlibby LogSnag