两个输入框 为正整数 且两个不能同时有值

vue2   input写法

 <FormItem
            :label="$t('follow.index.txt56')"
            v-if="followForm.leverType == 1"
          >
            <Select
              v-model="followForm.kcMultiple"
              :max-tag-count="2"
              :placeholder="$t('carouselItem.text52')"
            >
              <Option
                v-for="item in leverData"
                :value="item.value"
                :key="item.value"
                >{{ item.text }}</Option
              >
            </Select>
          </FormItem>
          <FormItem :label="$t('follow.index.txt58')">
            <Input
              type="number"
              style="width: 100%"
              v-model="followForm.fixSheets"
              :placeholder="$t('carouselItem.text269')"
            >
            </Input>
            <span
              style="position: absolute; top: 38px; right: 20px; color: #7c7f82"
              >{{ $t("swap.shareNumber") }}</span
            >
          </FormItem>

    
data() {
    return {    
        followForm: {
            fixSheets: "",
            fixBl: "",
      },
    }
}
watch: {
    followForm: {
      handler(newVal, oldVal) {
        if (newVal.fixSheets != "") {
          this.$nextTick(() => {
            this.followForm.fixBl = "";
          });
        }
        if (Number(newVal.fixSheets) > 1000) {
          this.$nextTick(() => {
            this.followForm.fixSheets = 1000;
          });
        }
        if (newVal.fixBl != "") {
          this.$nextTick(() => {
            this.followForm.fixSheets = "";
          });
        }
        if (Number(newVal.fixBl) > 5) {
          this.$nextTick(() => {
            this.followForm.fixBl = 5;
          });
        }
        if (newVal.fixSheets) {
          this.validatePositiveInteger(newVal.fixSheets, "fixSheets");
        }
        if (newVal.fixBl) {
          this.validatePositiveInteger(newVal.fixBl, "fixBl");
        }
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    validatePositiveInteger(value, fieldName) {
      const num = Number(value);
      if (isNaN(num) || !Number.isInteger(num) || num <= 0) {
        this.followForm[fieldName] = "";
        this.$Message.error(this.$t("carouselItem.text271"));
      }
    },
}

vue3   写法


        <uni-easyinput
          v-model="fixSheets"
          type="number"
          :clearable="false"
          :placeholder="$t('pact.follow.text13')"
          style="text-indent: 1rem"
        />
        <uni-easinput
          v-model="fixBl"
          type="number"
          :clearable="false"
          :placeholder="$t('pact.follow.text15')"
          style="text-indent: 1rem"
        />

const fixSheets = ref('')
const fixBl = ref('')

watch(
  () => fixSheets.value,
  (newVal) => {
    if (newVal != '') {
      nextTick(() => {
        fixBl.value = ''
      })
    }
    if (Number(newVal) > 1000) {
      nextTick(() => {
        fixSheets.value = 1000
      })
    }
  },
  { immediate: true },
)
watch(
  () => fixBl.value,
  (newVal) => {
    if (newVal != '') {
      nextTick(() => {
        fixSheets.value = ''
      })
    }
    if (Number(newVal) > 5) {
      nextTick(() => {
        fixBl.value = 5
      })
    }
  },
  { immediate: true },
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值