Show the array's selected value in a Vuetify select input

I am working with a dataset containing city names and corresponding values. The goal is to display the value when a city is selected. I know that {{selected.value}} will give me the selected value, but I need to manipulate this value for calculations such as adding 30 to it. To achieve this, I am attempting to use a computed value. However, I am facing an issue where I am unable to return just the value or a specific part of the array. When I use return this.selected, I can see the entire selected array, but when I try return this.selected.value or return.this.selected.name, I do not get any output.

Since I am new to vuejs, I am unsure about what I might be missing in my approach.

<template>
    <v-container fluid>
        <v-layout wrap align_center>
          <v-flex xs12 sm6>
            <v-select
              v-model="selected"
              :items="items"
              item-text= "city"
              item-value="value"
              :menu-props="{ maxHeight: '400'}"
              label="Select"
              hint="Pick your favorite states"
              multiple
              persistent-hint
              return-object
              single-line
            ></v-select>
          </v-flex>
          <v-flex>
                  {{getselection}}

          </v-flex>
        </v-layout>
        </v-container>

    </template>

    <script>

    export default {

        data () {
          return {
            text:'',
          selected: [],
          newsel: [],
          items:[
    {city: 'NY', value: 32},
    {city: 'Gent', value: 80},
    {city: 'Coimbra', value: 41}
     ]}
        },
  computed:{
    getselection(){
    return this.selected.value
    }
      },
      }
    </script>

Answer №1

To achieve the selection of a single item in the v-select component, consider removing the multiple prop:

<v-flex xs12 sm6>
            <v-select
              v-model="selected"
              :items="items"
              item-text= "city"
              item-value="value"
              :menu-props="{ maxHeight: '400'}"
              label="Select"
              hint="Pick your favorite states"
              persistent-hint
              return-object
              single-line
            ></v-select>
Check out the Vuetify Example Pen by boussadjra on CodePen: Vuetify Example Pen (@boussadjra)

If you still require the multiple prop, utilize the following computed property:

    getselection(){
    return !!this.selected.length ? this.selected[0].value : 0;
    }

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

Having trouble with fetch() not working in Next.JS while securing API Routes with auth.js

Currently, I am working on a project that involves user authentication using auth.js in next.js. The main goal is to create an API that retrieves specific user information from a MongoDB Database. The website itself is secured with middleware in next.js. I ...

Transform JSON-serialized string with HTML entities into an object

Looking for a solution to convert the following string into an object using Javascript: "[&quot;Software&quot;,&quot;3rd Party&quot;]" While I know how to convert HTML Entities to DOM Objects with this code: $("<div/>").html(encode ...

Button react-native press following textInput within scroll view aware of keyboard movements

I'm currently facing an issue where I have a TextInput and a button nested inside a KeyboardAwareScrollView. The goal is for the user to input some text and then tap the button created using TouchableOpacity, which should send the inputted text forwar ...

Learning to read HTML tags using JavaScript is a valuable skill

I've been struggling with a problem for some time now and I really need help fixing it. Here's the issue: I have an asp:GridView where I store text with HTML tags in my database under an English column. During the DataBound event, I use Context. ...

Activate fancybox after the AJAX content has finished loading

I have a <div> element with the id <div id="displayinformation"> where I am loading content dynamically using Ajax. Some of the loaded content contains links, and I want to display them in a Fancybox lightbox. I have confirmed that the Fancyb ...

React-Three/Fiber Vertical Sticky Carousel for Mobile Devices using Three.js

https://i.sstatic.net/Z5F8K0mS.gif After stacking the sticky areas, I faced a challenge in adding text in the same style. Additionally, I created refs for each phone scene but the stickiness was lost. I am uncertain about what caused it to stick initially ...

most efficient method to execute numerous API requests at the same time

Currently, I am developing a backend using expressJS. Imagine that I need to make 10,000 calls to an API consecutively and store the obtained data in a database. What would be the most effective approach for achieving this task? Is it possible that Promis ...

Experiencing an excessive amount of re-renders in React due to useState

In this scenario, the user is expected to press the correct letter on the keyboard (which is the first letter of the bird's name) in order to delete the first bird's name from the birds array. This process repeats until the array is empty. Howeve ...

Change the values of every element in an array

Looking to update the values of every item in an array list? if (country.hostel) { country.hostel.forEach(function (hostel, index) { hostel.room.forEach(function (room, index) { room = {code:{value: BOOKED}}; ...

Implementing jQuery in Ionic 3: A Step-by-Step Guide

I am attempting to display an external website within a div element using jQuery in Ionic 3. TS: export class HomePage { constructor(public navCtrl: NavController) { $('#loadExternalURL').load('http://www.google.com'); ...

Posting values using AJAX in PHP - A guide

test.html <html> <!-- To access the complete PHP-AJAX tutorial, please visit http://www.php-learn-it.com/tutorials/starting_with_php_and_ajax.html If you found this tutorial helpful, a backlink to it would be greatly appreciated. ...

Rearrange the arrangement of the array of objects

I am working with an array of objects that looks like this: [{ "Germany": "text", "Brazil": "50.00" }, { "Germany": "1000.00", "Brazil": "1100.00" }, { "Germany& ...

Reconstructing a file from a string using the FileReader in reverse

Converting the file to a string: const reader = new FileReader() reader.readAsText(file, 'UTF-8') reader.onload = (event) => { this.textFile = event.target.result }; Upon uploading a Zip, Text, or Image file, my string appears as: data:t ...

Failure in jQuery AJAX POST request

Attempting to make an ajax post request function ajaxCall(request_data) { alert(request_data['table'] + request_data['name'] + request_data['description']); $.ajax({ type: "POST", cache: false, url: "../src/api.ph ...

Generating npm package without including file extensions in imports

I am currently working on creating an internal library for my workplace. Everything seems to be going smoothly until I try to use it in another project. It appears that the file extension in all of the import statements has disappeared during the npm pack ...

The successful JSON response in an Ajax request is not functioning as expected

I've set up a data table that allows users to add rows by clicking the "plus" button. This triggers an ajax request to a URL with the rowId as a parameter (which corresponds to the specific row where the button was clicked). I expect to receive a JSON ...

Using an image within the input group in Bootstrap 4

I'm a beginner in web development and I'm currently utilizing the glyphicon. This is how I'm currently using it: const className = `form-group ${touched && error ? 'has-danger' : ''}`; <div className={classN ...

Adding data to an array using jQuery

I have a list of items called data and an empty array called quotations: var data = {}; var quotations = []; My goal is to populate the quotations array with data values. Each time I add new data, it is successfully added, but all data values end u ...

Ways to identify when a jQuery ajax request has finished executing?

Currently, I have a dropdown menu of countries that is populated using a jQuery ajax call. The issue I am facing is determining when the call is complete so that I can correctly select a country afterwards. Any function I call after the ajax function is tr ...

Divide the identical elements and distinct elements from a provided array into two separate arrays storing unique elements and recurring elements

Can anyone help me with this query? I have an array of objects that need to be separated into repeating and non-repeating objects based on the segments they belong to, each in a separate array. For example- [ {name:"abc",id:1,segments:[1,2]}, {n ...