Skip to content

Latest commit

 

History

History
74 lines (57 loc) · 2.06 KB

guide-en-custom-component.md

File metadata and controls

74 lines (57 loc) · 2.06 KB

Guide to developing custom component

Preface

In some scenario, for personalized needs, such as rendering an upload component, common form items can not meet the demand. You may want to develop a custom form item. At this time, the component option can help.

This article will describes how to develop custom component that el-form-renderer can render.

How To

The key point of writing custom component is to implement v-model inside the component in this manner:

  • a props name value
  • emit input event

Example

<!-- custom component: my-input -->
<input :value="value" @input="onInput">

<script>
export default {
  props: {
    value: String
  },
  methods: {
    onInput(val) {
      this.$emit('input', 'my-input: ' + val)
    }
  }
}
</script>

Now @femessage/el-form-renderer can render this custom input component via component option

<template>
  <el-form-renderer :content="content"/>
</template>

<script>
import MyInput from '@/components/my-input.vue'
export default {
  data() {
    return {
      content: [
        {
          component: MyInput,
          id: 'myInput',
          label: 'label'
        }
      ]
    }
  },
}
</script>

More Cases

Here is a list of components that we can use @femessage/el-form-renderer to render without writing template.

Read More