0

I want v-model="num" just when the v-if prop === 'amount'. How can i do it? because the input is common to 'qty' and 'book_value'

<template #item="{ prop, value, rowIndex }">
    <div
    v-if="prop === 'qty' || prop === 'book_value'"
    >
    <input
      v-model="num"
      :value="preview && prop === 'book_value'? formatAmount(value) : value"
      :preview="preview"
       @input="setRuleItem({ newValue: $event, prop, rowIndex, name: 'actions' })"
     />

---------------------------

watch: {
    num (newVal, oldVal) {
      if (newVal.includes('.')) {
        this.$nextTick(() => { this.num = newVal.split('.')[0] + '.' + newVal.split('.')[1].slice(0, 2) })
      }
    }
  },
1
  • Not clear at all. Commented Jul 29, 2021 at 16:01

1 Answer 1

1

You can do it in many ways, but here are some simple examples

Use input handler instead of v-model

<input @input="(val) => prop === 'amount' ? num = val : false" :value ... />

create another element

<input v-if="prop === amount" v-model="num"...><input v-else :value... ></input>
Sign up to request clarification or add additional context in comments.

1 Comment

Of which the second is less likely to break, although it does double the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.