D
D
Dutymy2021-09-26 00:39:15
Vue.js
Dutymy, 2021-09-26 00:39:15

How to use computed with v-model?

Hello, I have an input with

v-model="value" //переменная привязки
:value="computedValue"
//default value
unfortunately it is not possible to throw the default value immediately into value when mounted, since the input only starts to exist if the v-if is mounted much later, how can I add the default value in combination with v-model...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GrayHorse, 2021-09-26
@Dutymy

What?
The default value in the conditional input:
https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXR...

<template>  
  <label>
    <input v-model="checked" type="checkbox">
    Show input
  </label>
  <br>
  <input v-if="checked" v-model="msg">
</template>

<script setup>
import {ref} from "vue";

const msg = ref("Hello World!");
const checked = ref(false);
</script>

On Vue 2, everything is the same.
It just works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question