Home  >  Q&A  >  body text

Two-way form data binding in Vue 3 composition api

I'm starting to transition from the options api to the composition api in vue.

I have the following block of code that I'm trying to implement a 2 way binding.

I am using ant-design-vue library for slider input. and try to bind the slider value to the input field.


<template>
  <div>
    <a-row>
      <a-col :span="12">
        <a-slider v-model="inputValue1" :min="1" :max="20" />
      </a-col>
      <a-col :span="4">
        <a-input-number
          v-model="inputValue1"
          :min="1"
          :max="20"
          style="marginleft: 16px"
        />
      </a-col>
    </a-row>
  </div>
</template>
<script>
import { ref } from "vue";
export default {
  setup() {
    let inputValue1 = ref(8);
    return { inputValue1 };
  },
};
</script>


Using the above code, the value of inputValue1 will not change when checked in the vue development tool.

How to use two methods of binding in vue 3 combination api?

Link to sandbox: https://stackblitz.com/edit/vue-pchhub?file=src/App.vue

P粉982881583P粉982881583276 days ago530

reply all(1)I'll reply

  • P粉237029457

    P粉2370294572023-12-07 09:47:03

    Looks like you have to use v-model:value="..." for this to work.

    
    sssccc

    reply
    0
  • Cancelreply