source

Bootstrap-Vue 텍스트 필드를 mm/dd/yyy 형식으로 변경하는 적절한 방법

goodcode 2022. 8. 25. 23:49
반응형

Bootstrap-Vue 텍스트 필드를 mm/dd/yyy 형식으로 변경하는 적절한 방법

Bootstrap-Vue를 사용하고 있습니다.<b-form-datepicker>컴포넌트 및 입력 날짜 필드를 커스터마이즈할 방법을 찾고 있습니다.mm/dd/yyyy포맷합니다.적절한 방법이 있나요?

<b-input-group class="mb-3">
        <b-form-input
          id="example-input"
          v-model="dateOfBirth"
          type="text"
          placeholder="MM-DD-YYYY"
          locale="en-US"
          autocomplete="off"
        ></b-form-input>
        <b-input-group-append>
          <b-form-datepicker
            v-model="dateOfBirth"
            button-only
            right
            locale="en-US"
            :date-format-options="{ year: 'numeric', month: 'short', day: '2-digit', weekday: 'short' }"
            aria-controls="example-input"
          ></b-form-datepicker>
        </b-input-group-append>
      </b-input-group>

매뉴얼 https://bootstrap-vue.org/docs/components/form-datepicker

이 작업을 수행하려면 단순히 다음 작업을 할당해야 합니다.selectedFormatted로부터 값을 매기다.b-form-datepickerv-model의 가치b-form-input.

참고: 둘 다 다른 v-model 값을 사용합니다.b-input-group&b-form-datepicker

데모:

new Vue({
  el: '#app',
  data() {
    return {
      value: '',
      inputValue: ''
    }
  },
  methods: {
    onContext(ctx) {
      this.inputValue = ctx.selectedFormatted;
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<link rel="stylesheet" href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>
<link rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<div id="app">
  <label for="example-input">Choose a date</label>
  <b-input-group class="mb-3">
    <b-form-input
      id="example-input"
      v-model="inputValue"
      type="text"
      placeholder="MM/DD/YYYY"
      autocomplete="off"
    ></b-form-input>
    <b-input-group-append>
      <b-form-datepicker
        v-model="value"
        button-only
        right
        locale="en-US"
        aria-controls="example-input"
        :date-format-options="{ year: 'numeric', month: 'numeric', day: 'numeric' }"
        @context="onContext"
      ></b-form-datepicker>
    </b-input-group-append>
  </b-input-group>
</div>

각 구성 요소를 숫자로 설정하면 올바른 형식이 되지 않습니까?

<b-form-datepicker
  :date-format-options="{ year: 'numeric', month: 'numeric', day: 'numeric' }"
  locale="en"
></b-form-datepicker>

제공 내용:9/16/2020

언급URL : https://stackoverflow.com/questions/63911689/proper-way-to-change-bootstrap-vue-text-field-into-mm-dd-yyyy-format

반응형