0

如果评估费输入具有输入值,我需要找到一种方法来基本上在评估期间输入中显示“每月”。

我已经尝试过绑定和组件,但无法做到这一点。

            <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>



  data() {
    return {
      now: new Date().toISOString(),
      document: {
        assessments_fee: '',
        assessments_period: '',
      }
    }
  },



      components: {
        assessments_fee: function() {
          if(this.assessments_fee != null || '') this.assessments_period = "per Month";
        }
      },
4

1 回答 1

0

你可以创建一个观察者,assessments_fee所以当它不是时null assessments_period= 'per Month'

您可以这样做:

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>

于 2019-08-08T15:28:40.030 回答