Bidirectional data binding in the Vue 3 composition API

Currently, I am in the process of transitioning from the options API to the composition API in Vue.

Within the code block below, I am attempting to implement two-way binding.

I am utilizing the ant-design-vue library for a slider input and trying to bind the slider value to an 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>

In the provided code snippet, the value of inputValue1 does not update when inspected using the Vue Dev Tools.

How can I achieve two-way binding with Vue 3 Composition API?

Sandbox link: https://stackblitz.com/edit/vue-pchhub?file=src%2FApp.vue

Answer №1

It appears that you need to utilize v-model:value="..." in order for this solution to function.

<template>
  <div>
    <a-row>
      <a-col :span="12">
        <a-slider v-model:value="inputValue1" :min="1" :max="20" />
      </a-col>
      <a-col :span="4">
        <a-input-number
          v-model:value="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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular 2 template is nowhere to be found

As a newcomer to Angular 2, I am currently developing an app where I have successfully completed the Root component containing a navigation bar and footer. However, as I delve into working on the homepage module, I encountered an error. [Error] Unhandle ...

AngularJS encounters failure during shared data service initialization

As a newcomer to AngularJS, I aim to develop an application in adherence to John Papa's AngularJS style guide. To familiarize myself with these best practices, I have opted for the HotTowel skeleton. My application requires consuming an HTTP API endp ...

Is there a way to retrieve the objects generated by DirectionsRenderer on Google Maps V3?

Is there a simple method to access the objects and properties of the markers and infowindows that are generated by the DirectionsRenderer? (such as the "A" and "B" endpoints of the route) I want to swap out the infowindows for the "A" & "B" markers wi ...

Do we need to utilize a server folder in Nuxt 3 if we have API endpoints?

In Nuxt 3, there is a dedicated server folder containing an api subfolder. Why should we utilize this when we already have API endpoints built with a server-side programming language like Laravel? Are they linked in any way? For instance, consider these ...

Tips for preserving scroll location on Angular components (not the window) when navigating

My current layout setup is like this: https://i.sstatic.net/hOTbe.png In essence <navbar/> <router-outlet/> The issue I'm facing is that the router-outlet has overflow: scroll, making it scrollable (just the outlet section, not the ent ...

Node.js allows you to seamlessly upload multiple images from various form fields or input types simultaneously

<form action="/upload-images" method="post" enctype="multipart/form-data"> <input type="file" name="image1" /> <input type="file" name="image2" /> <input type= ...

AngularJS $scope variable can be initialized only once using an HTTP GET request

I'm facing an issue with fetching data from an API in a separate AngularJS application. There's a button that triggers the retrieval of data from the API. Upon clicking, it executes the $scope.getApiData function, which is connected to $scope.pr ...

Error in Vite and Vue: Unable to access properties of undefined when trying to read 'checkedNumbers'

Customized template <script setup> import { computed, ref, watch } from "vue"; let checkedNumbers = ref([]); function sum(){ return this.checkedNumbers.reduce(function (a, b) { return parseFloat(a)+ parseFloat(b); },0); } <span id="p ...

Error: JavaScript function call did not provide a return value

Currently, I am in the process of creating a straightforward angular2/expressJS application. Within my expressJS code, I have an HTTP GET router call that retrieves all users from MongoDB and successfully returns them: app.get('/getusers', funct ...

Error: VueJS - The Vue object has not been declared

Embarking on a challenge, I have set out to create an application that pulls data from an API and showcases it in various components. As a newcomer to VueJS, I rely on VueResource for accessing the API and VueX for managing the state of my application. Aft ...

When using the `Document.write()` method, an error is returned stating, "Uncaught TypeError: Cannot read property 'document' of null"

I am currently integrating Angular2 into a website as the front-end framework, and it will be displayed on another website using an iframe. When working with the HTTP post method, I am able to receive a JSON response. Here is the API Post method that retu ...

Executing a Python function using JavaScript: Step-by-step guide

I am facing an issue with invoking my python function from my javascript file. Running a simple server with python3 -m http.server, I have no backend and all my javascripts are on the front end. In a python file named write.py, there is a function that I ...

Differences between Typescript Import and JavaScript import

/module/c.js, attempting to export name and age. export const name = 'string1'; export const age = 43; In b.ts, I'm trying to import the variables name and age from this .ts file import { name, age } from "./module/c"; console.log(name, ...

Tips for creating a script that compiles all SCSS files into CSS within a Vue 3 project

Within my project, there exists a file named index.scss located in the src/assets/styles directory. Adjacent to this file are multiple folders housing SCSS files that are ultimately imported into index.scss. My objective is to devise a script within the pa ...

Rendering Radial Gradients Using CSS3 in Google Chrome

While experimenting with animating radial gradients using jQuery, I came across an interesting observation (take a look at this JSFiddle). As I moved the mouse pointer over the left side of the element, the position animation appeared smooth. However, movi ...

What is the best way to ensure that my threejs mesh only tracks my mouse movements along the x-axis?

Trying to create a threejs mesh that responds to mouse movement by moving from side to side, but encountering an issue when changing directions. Below is the code snippet for the mousemove function: The problem arises when switching directions after init ...

What are the steps for skipping, sorting, and limiting with dynamoose?

After being familiar with MongoDB and mongoose, I am now exploring dynamoose for my app. In order to replicate the below-shown mongoose query using dynamoose, how can I write it? Specifically, I want to achieve the same functionality as the following mong ...

Can you show me how to nest components in Vue.js?

Just dipping my toes into the world of vue and attempting to migrate an old-fashioned Bootstrap app to a BS5 + vue3 setup. The goal is to recreate something like this: using a json object fetched from an api. Currently, it consists of four nested arrays o ...

Determine the height of an element within an ng-repeat directive once the data has been fetched from an

After sending an ajax request to fetch a list of products, I use angular's ng-repeat to render them. I am attempting to retrieve the height of a div element that contains one product in the list. However, the console always displays "0" as the result ...

Prevent inheriting styles with jQuery Else / If conditions

I'm seeking advice on how to prevent elements from retaining the same inline styles in different breakpoints. My goal is to adjust styling based on window width, similar to CSS media queries, but with the additional need to increment a numeric value ...