Kamal Nasser

Blog HomePersonal Website

Transparent Vue Wrapper Components

Lifted from 7 Secret Patterns Vue Consultants Don’t Want You to Know - Chris Fritz

Component Definition

BaseInput.vue

<template>
    <label>
        {{ label }}
        <input
          v-bind="$attrs"
          :value="value"
          v-on="listeners"
        >
    </label>
</template>

Usage

<BaseInput
  placeholder="What's your name"
  @focus="doSomething"
/>

This will bind all attributes and event listeners set on the component to the <input> element.

Thoughts? Comments?

Find me on Twitter @kamaln7 or somewhere else.