[Vuejs]-How do I use one input to control the other in vuejs

0👍

you can create a watcher for assessments_fee so when its not null assessments_period= 'per Month'.

Here is how you can do it:

new Vue({
  el: '#app',
  data() {
    return {
      now: new Date().toISOString(),
      document: {
        assessments_fee: '',
        assessments_period: '',
      }
    }
  },
  computed: {
    assessmentsFee() {
      return this.document.assessments_fee
    }
  },
  watch: {
    assessmentsFee() {
      this.document.assessments_fee ?
      this.document.assessments_period = "per Month" :
      this.document.assessments_period = ""
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div class="col-lg-6">
    <div class="form-group">
      <label>Assessment Fee <span class="note">C</span></label>
      <input type="text" class="form-control" v-model="document.assessments_fee" placeholder="$">
    </div>
  </div>
  <div class="col-lg-6">
    <div class="form-group">
      <label>Assessment Period <span class="note">C</span></label>
      <input type="text" class="form-control" v-model="document.assessments_period" placeholder="(per month/quarter/etc.)">
    </div>
  </div>
</div>

Leave a comment