C
C
ceeed2021-07-05 21:09:11
Vue.js
ceeed, 2021-07-05 21:09:11

How can I make a default value in input using interpolation?

I need to pass the default input value from the model that I have in data. So that when rendering there would be a value that I could then change. You need to make max_slippage the default value. How can I achieve this?

<teamplate>
 <input class="input border border-gray-400 appearance-none rounded w-full px-3 py-3 pt-5 pb-2 focus focus:border-indigo-600 focus:outline-none active:outline-none active:border-indigo-600" v-model="name" name="inputSlipage" id="slipage" type="text">
{{ max_slippage }}
</template>
<script>
 data() {
   return {
     max_slippage: null,
}
}
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-07-05
@Aetae

If I understood you correctly:

<template>
  <input
    class="input border border-gray-400 appearance-none rounded w-full px-3 py-3 pt-5 pb-2 focus focus:border-indigo-600 focus:outline-none active:outline-none active:border-indigo-600"
    :value="name === null ? max_slippage : name"
    @input="name = $event.target.value"
    name="inputSlipage"
    id="slipage"
    type="text"
  >
</template>

<script>
  export default {
    data() {
      return {
        max_slippage: null,
        name: null
      }
    }
  }
</script>

PS You obviously overdid it with universal classes. Better use sass with variables and mixins.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question