Vue

by WILLIAM CORREA

HTML

<div id="app">
  <template v-for="(field, key) in fields">
    <div :key="key">
    {{ field.label }}:
    <component
        :is="field.is"
        v-bind="field.attrs"
        v-on="field.listeners"
        :value="record[key]"
        @input="record[key] = $event.target.value" 
      ></component>
    </div>
  </template>
  <pre>{{ record }}</pre>
  <pre>{{ fields }}</pre>
</div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

del {
  color: rgba(0, 0, 0, 0.3);
}

Vue

new Vue({
  el: "#app",
  data: () => ({
  	record: {
    	name: 'William',
      age: 12
    },
    fields: {
    	name: {
      	is: 'input',
        label: 'Name',
        attrs: {
        	placeholder: 'My name'
        },
        listeners: {}
      },
    	age: {
      	is: 'input',
        label: 'Age',
        attrs: {
        	placeholder: 'My age',
          type: 'number'
        },
        listeners: {
        	input ($event) {
          	window.alert($event.target.value)
          }
        }
      }
    }
  })
})