In Vue.js, the v-model connects a value that can be easily changed to a different value

I just connected the second input box to v-model of changedPrice.c1

Currently, it is set to display roundFee as $5000. However, the second input box allows for new input numbers.

In this scenario, I am unsure which method to use. Should I go with computed? or @change? Can someone please provide me with a comprehensive answer? Thank you in advance to anyone who can assist me.

script

data() {
    return {
         roundFee : 5000,
         changedPrice: {
             c1: 0,
             c2: 0,
         }
     }
 }

vue.js

 <input type="text" class="form-control" disabled v-model="roundFee"> $
 <input type="text" class="form-control" v-model="changedPrice.c1"> $

Answer №1

To utilize a computed setter, you can follow this example:

data() {
    return {
         roundFee : 5000,
         changedPrice: {
             c1: 0,
             c2: 0,
         }
     },
     computed: {
         secondInput: {
             get() {
                 return this.roundFee;
             },
             set(newValue) {
                 this.changedPrice.c1 = newValue;
             }
         }
     }
 }

Afterwards, connect the computed property secondInput to your input

<input type="text" class="form-control" disabled v-model="roundFee"> $ 
<input type="text" class="form-control" v-model="secondInput"> $

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

Is there a way to choose multiple dropdown items that share the same header?

Utilizing the Fluent UI React Northstar Dropdown component in my React project, I've encountered an issue with multiple item selection. It seems that when there are several items sharing the same header value, only one can be selected at a time. What ...

`Count the number of rows needed to accommodate text line breaks within a div element`

Is there a method to determine the number of lines that text breaks into using the CSS property word-break: break-all? For example, if I have a div like this: <div>Sample text to check how many lines the text is broken into</div> And the corr ...

Converting JSON data into GeoJSON format using JavaScript

Currently, I am in the process of reading a JSON file and formatting it for GeoJSON function getAddress(id,search,vagas, next) { geo.geocode({address:search}, function (results,status) { if (status == google.maps.GeocoderStatus.OK) { ...

JavaScript Tip: How to Capture the Enter Key without Using a JavaScript Framework

Is there a way to identify when the "Enter" key is pressed in the window and potentially prevent it? I have come across various methods using jQuery and MooTools, but haven't found a solution that doesn't rely on a framework. Any suggestions woul ...

Create a website specifically designed to showcase the functionality and capabilities of an API

As a junior front-end developer, I am looking to build a simple API. I have already deployed a mock version of this API on Heroku (accessible at this link) using Express. My goal is to create a website with Vue.js where the root path is dedicated to the w ...

Utilize AJAX to insert information into a MySQL database when a checkbox is selected

Before I got stuck here, I took a look at how a similar question was implemented here I attempted to implement the code in order to insert data into a MySQL database when a checkbox is clicked. While it may have been easier to do this on form submission, ...

Having trouble with Three JS shadows not displaying correctly?

I recently built an interactive 3D model on my website using ThreeJS, but I'm facing an issue with getting the shadows to work properly. As a beginner in ThreeJS, I might be missing out on some crucial steps. Below is the JavaScript code I've us ...

Issues with Angular Component not detecting changes in @Input array

I'm dealing with a challenging setup where: The Parent Service (A) is imported in the Parent Component (B). Then, the Parent Component passes an array of Objects to a Child Component (C), which are referenced from the Parent Service (e.g. <child-c ...

What are some solutions for resolving a background image that fails to load?

HTML: `<div class="food-imagesM imagecontainer"> <!--Page info decoration etc.--> </div>` CSS: `.food-imagesM.imagecontainer{ background-image: url("/Images/Caribbean-food-Menu.jpg"); background-repeat: no-repeat; backgroun ...

How can I use Angular to add ng-class to a parent element when a checkbox is selected?

I am working on a parent list with a dropdown of checkboxes that only shows when you click on the list. Currently, all lists receive the class "active" if any checkbox in any list is checked. However, I want to change this behavior so that only the list co ...

Check the presence of a specific cell within an array of cells

Currently, I am attempting to navigate through a spreadsheet column while disregarding any duplicate values. My approach involves using TextFinder to gather all cells with matching values and then adding them to an array named "duplicates." Throughout eac ...

Combining D3 and D3plus in an Angular web application: A complete guide

I'm currently integrating d3Plus sample code () into my angular-based webapp. This is the initial setup code: angular.module('UI', ['UI.controllers', 'UI.directives']); angular.module('d3Plus', ['d3' ...

The problem arises when using `$state.go` as it does not properly transfer the value to `$stateParams`

Within componentA, I am using an angular code: $state.go('home', {selectedFilter: "no_filter"}); In componentB, I have the following code: if ($stateParams.selectedFilter === 'no_filter') However, I am encountering an issue where $s ...

Performing a Jquery ajax post to an MVC2 action

I have a script set up to send a POST request to an endpoint, and it seems like the routing is correct as it hits the breakpoint on the server. $(document).ready(function() { var o = new Object(); o.message = 'Hi from the page'; $.ajax({ ...

Can you provide guidance on how to showcase a list?

What is the correct way to display a list received through a URL in JSON format? Here is an example project. When using a local variable everything works fine, but when trying to fetch the list from a URL, an error is displayed. constructor(props) { ...

How can I create a textbox in vue.js that only allows numeric input?

methods: { acceptNumber() { var x = this.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/); this.value = !x[2] ? x[1] : '(' + x[1] + ')' + x[2] + (x[3] ? '-' + x[3] : & ...

Unable to install Vue/CLI on Ubuntu 20.04 due to permission denial

Attempting to set up Vue CLI on Ubuntu 20.04 using the given command: sudo npm install -g @vue/cli Encountered a permission denied error: 2021/06/13 14:35:24.163955 cmd_run.go:1002: WARNING: cannot create user data directory: cannot create "/nonexist ...

Progress bar in Angular that displays during all asynchronous operations in ngOnInit

In order to make users wait until all necessary data is retrieved, I would like to implement a progress bar using this library. The challenge lies in handling multiple HTTP requests and knowing when all calls have been completed so that the waiting bar ...

Images are not appearing on Github pages

My website on GitHub Pages is not displaying images properly. Here is the link to my site: However, when I run it locally everything works fine. You can find the repository here: https://github.com/rsgrw23/rate-your-beer Can anyone pinpoint what might be ...

"Customize the look of the action button in Material-UI's

Is there a way to customize the appearance of action buttons within a Dialog, DatePicker, or TimePicker by accessing the containing div? I'm looking to add padding between these buttons and potentially change the background color of the div generated ...