Skip to content

EwVueComponentPowerful Vue 3 Dynamic Component Wrapper

Easily implement dynamic component switching, error handling, and performance optimization

EwVueComponent โ€‹

A powerful Vue 3 dynamic component library that makes component switching, async loading, and error handling effortless.

๐Ÿš€ Features โ€‹

Core Capabilities โ€‹

  • Dynamic Component Switching: Seamlessly switch between strings, component objects, and async components
  • Intelligent Error Handling: Built-in error boundaries with automatic fallback to backup components and retry mechanisms
  • Performance Optimization: Component caching, performance monitoring, and intelligent loading
  • Type Safety: Complete TypeScript support for excellent development experience
  • Plugin System: Extensible plugin architecture with built-in logging, performance, and error handling plugins

Advanced Features โ€‹

  • Async Component Support: Code splitting and lazy loading with loading states
  • Component Caching: Local and global caching with TTL support
  • Error Recovery: Automatic retry mechanisms and custom error components
  • Performance Monitoring: Built-in performance tracking and optimization
  • Props/Events/Slots Forwarding: Complete transparency for component integration

๐Ÿ“ฆ Installation โ€‹

bash
# npm
npm install ew-vue-component

# yarn
yarn add ew-vue-component

# pnpm
pnpm add ew-vue-component

๐ŸŽฏ Quick Start โ€‹

1. Basic Usage โ€‹

vue
<template>
  <div>
    <!-- String component (HTML tag) -->
    <EwVueComponent is="button" @click="handleClick">
      Click me!
    </EwVueComponent>
    
    <!-- Vue component -->
    <EwVueComponent :is="MyComponent" :title="title" />
    
    <!-- Async component -->
    <EwVueComponent :is="asyncComponent" @error="handleError" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { EwVueComponent } from 'ew-vue-component'
import MyComponent from './MyComponent.vue'

const title = ref('Hello World')
const asyncComponent = () => import('./AsyncComponent.vue')

const handleClick = () => {
  console.log('Button clicked!')
}

const handleError = (error) => {
  console.error('Component failed to load:', error)
}
</script>

2. With Error Handling โ€‹

vue
<template>
  <EwVueComponent 
    :is="currentComponent"
    :fallback="FallbackComponent"
    :error-component="ErrorComponent"
    @error="handleError"
  >
    <template #default>
      <p>Loading...</p>
    </template>
  </EwVueComponent>
</template>

<script setup>
import { ref, h } from 'vue'
import { EwVueComponent } from 'ew-vue-component'

const currentComponent = ref('UnstableComponent')

const FallbackComponent = {
  render() {
    return h('div', 'Fallback content when component fails')
  }
}

const ErrorComponent = {
  props: ['error', 'retry'],
  render() {
    return h('div', [
      h('h3', 'Something went wrong'),
      h('p', this.error?.message),
      h('button', { onClick: this.retry }, 'Retry')
    ])
  }
}

const handleError = (error) => {
  console.error('Component error:', error)
  // Send to error monitoring service
}
</script>

3. With Performance Optimization โ€‹

vue
<template>
  <EwVueComponent 
    :is="heavyComponent"
    :cache="true"
    :cache-key="cacheKey"
    :cache-ttl="300000"
    :plugins="[performancePlugin, logPlugin]"
  />
</template>

<script setup>
import { ref, computed } from 'vue'
import { EwVueComponent } from 'ew-vue-component'

const heavyComponent = () => import('./HeavyComponent.vue')
const componentId = ref('heavy-1')

const cacheKey = computed(() => `heavy-component-${componentId.value}`)

const performancePlugin = {
  name: 'performance',
  beforeRender(component, props, context) {
    performance.mark('component-render-start')
  },
  afterRender(component, props, context) {
    performance.mark('component-render-end')
    performance.measure('component-render', 'component-render-start', 'component-render-end')
  }
}

const logPlugin = {
  name: 'logger',
  beforeRender(component, props, context) {
    console.log('Rendering component:', component.name || component)
  }
}
</script>

๐Ÿ”ง Component Types โ€‹

EwVueComponent supports multiple component types:

TypeExampleUse Case
String"div", "button"HTML tags, simple elements
ComponentMyComponentRegular Vue components
Async Function() => import('./Async.vue')Code splitting, lazy loading
Component Object{ render() { ... } }Dynamic render functions

๐Ÿ›ก๏ธ Error Handling โ€‹

Error Events โ€‹

vue
<EwVueComponent 
  :is="component"
  @error="handleError"
/>

Fallback Components โ€‹

vue
<EwVueComponent 
  :is="component"
  fallback="div"
/>

Custom Error Components โ€‹

vue
<EwVueComponent 
  :is="component"
  :error-component="CustomErrorComponent"
/>

โšก Performance Features โ€‹

Component Caching โ€‹

vue
<EwVueComponent 
  :is="component"
  :cache="true"
  :cache-key="uniqueKey"
  :cache-ttl="300000"
/>

Performance Monitoring โ€‹

vue
<EwVueComponent 
  :is="component"
  :plugins="[performancePlugin]"
/>

๐Ÿ”Œ Plugin System โ€‹

Built-in Plugins โ€‹

  • Log Plugin: Component lifecycle logging
  • Performance Plugin: Render time monitoring
  • Error Plugin: Advanced error handling and reporting

Custom Plugins โ€‹

javascript
const customPlugin = {
  name: 'my-plugin',
  beforeRender(component, props, context) {
    // Before render logic
  },
  afterRender(component, props, context) {
    // After render logic
  },
  onError(error, context) {
    // Error handling logic
  }
}

๐Ÿ“– Documentation โ€‹

Guides โ€‹

API Reference โ€‹

Examples โ€‹

๐ŸŒŸ Use Cases โ€‹

Dynamic Forms โ€‹

Build forms with dynamic field types based on configuration:

vue
<EwVueComponent 
  v-for="field in formFields"
  :key="field.id"
  :is="field.component"
  v-bind="field.props"
  @input="updateField(field.id, $event)"
/>

Micro-frontends โ€‹

Load remote components dynamically:

vue
<EwVueComponent 
  :is="() => loadRemoteComponent(appUrl)"
  :cache="true"
  @error="handleMicrofrontendError"
/>

Content Management โ€‹

Render dynamic content based on CMS data:

vue
<EwVueComponent 
  v-for="block in contentBlocks"
  :key="block.id"
  :is="componentMap[block.type]"
  v-bind="block.props"
/>

A/B Testing โ€‹

Switch between component variants:

vue
<EwVueComponent 
  :is="experimentVariant"
  :plugins="[analyticsPlugin]"
/>

๐Ÿš€ Why EwVueComponent? โ€‹

Traditional Approach โ€‹

vue
<template>
  <div>
    <ComponentA v-if="type === 'a'" v-bind="props" />
    <ComponentB v-else-if="type === 'b'" v-bind="props" />
    <ComponentC v-else-if="type === 'c'" v-bind="props" />
    <!-- Manual error handling for each component -->
  </div>
</template>

With EwVueComponent โ€‹

vue
<template>
  <EwVueComponent 
    :is="componentMap[type]"
    v-bind="props"
    :fallback="FallbackComponent"
    @error="handleError"
  />
</template>

๐Ÿค Contributing โ€‹

We welcome contributions! Please see our Contributing Guide for details.

Development Setup โ€‹

bash
# Clone the repository
git clone https://github.com/eveningwater/ew-vue-component.git

# Install dependencies
pnpm install

# Run tests
pnpm test

# Build the library
pnpm build

๐Ÿ“„ License โ€‹

MIT License - see the LICENSE file for details.

๐Ÿ’ก Support โ€‹


Made with โค๏ธ by the EwVueComponent team

Released under the MIT License.