vuejs:vue3:labeled_input_form

Vue.js 3.x LabeledInputForm コンポーネント

  • input の以下のタイプを実装するラベル付きコンポーネント
    • text
    • password
    • email
    • url
    • number
    • date
    • time
  • v-model 対応
  • 再利用可能なコンポーネントとする。
  • 指定可能な属性が異なるため、$attr をバインドするが、対応できない場合は別のコンポーネントとしてで作成する。
LabeledInputForm.js
import LabeledForm from '/_export/code/vuejs/vue3/labeled_form?codeblock=0';
import InputForm   from '/_export/code/vuejs/vue3/input_form?codeblock=0';
 
const LabeledInputForm = {
  template: `
    <labeled-form
      :errors="errors"
      :label-text="labelText"
      :form-wrapper-classes="formWrapperClasses"
      :form-wrapper-styles="formWrapperStyles"
      :label-wrapper-classes="labelWrapperClasses"
      :label-wrapper-styles="labelWrapperStyles"
      :form-error-class="formErrorClass"
      :label-error-class="labelErrorClass"
    >
      <template #label v-if="!labelText">
        <slot name="label">
        </slot>
      </template>
      <input-form
        :type="type"
        v-bind="$attrs"
        :value="value"
        @update:value="updateValue"
        :errors="errors"
        :control-wrapper-classes="controlWrapperClasses"
        :control-wrapper-styles="controlWrapperStyles"
        :control-classes="controlClasses"
        :control-styles="controlStyles"
        :control-error-class="controlErrorClass"
        :message-wrapper-classes="messageWrapperClasses"
        :message-wrapper-styles="messageWrapperStyles"
        :message-error-class="messageErrorClass"
      >
      </input-form>
    </labeled-form>
  `,
  components: {
    labeledForm: LabeledForm,
    inputForm: InputForm
  },
  props: {
    type:                  { type: String, default: 'text' },
    value:                 { type: String },
    errors:                { type: Array,  default: [] },
    labelText:             { type: String },
    formWrapperClasses:    { type: Array,  default: [] },
    formWrapperStyles:     { type: Object, default: {} },
    labelWrapperClasses:   { type: Array,  default: [] },
    labelWrapperStyles:    { type: Object, default: {} },
    controlWrapperClasses: { type: Array,  default: [] },
    controlWrapperStyles:  { type: Object, default: {} },
    controlClasses:        { type: Array,  default: [] },
    controlStyles:         { type: Object, default: {} },
    messageWrapperClasses: { type: Array,  default: [] },
    messageWrapperStyles:  { type: Object, default: {} },
    formErrorClass:        { type: String, default: 'has-error' },
    labelErrorClass:       { type: String, default: 'text-danger' },
    controlErrorClass:     { type: String, default: 'is-invalid' },
    messageErrorClass:     { type: String, default: 'text-danger' },
  },
  setup(props, context) {
    function updateValue(v) {
      context.emit('update:value', v)
    }
    return { updateValue }
  }
};
export default LabeledInputForm;
  • type: String
  • default: 'text
  • type: String
  • type: Array
  • default: []
  • type: String
  • type: Array
  • default: []
  • type: Object
  • default: {}
  • type: Array
  • default: []
  • type: Object
  • default: { paddingTop: '7px' }
  • type: Array
  • default: []
  • type: Object
  • default: {}
  • type: Array
  • default: []
  • type: Object
  • default: {}
  • type: Array
  • default: []
  • type: Object
  • default: {}
  • type: String
  • default: 'has-error'
  • type: String
  • default: 'text-danger'
  • type: String
  • default: 'has-error'
  • type: String
  • default: 'text-danger'

  • vuejs/vue3/labeled_input_form.txt
  • 最終更新: 2021/01/26 09:48
  • by admin