Two-way form data binding in Vue 3 composition api
P粉982881583
P粉982881583 2023-12-06 10:55:35
0
1
485

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粉982881583
P粉982881583

reply all(1)
P粉237029457

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


sssccc
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!