Creating a dynamic dropdown menu to display nested arrays in Vuejs

I have some important data

https://i.sstatic.net/Cq2t6.png

Challenge

I'm facing difficulty in accessing the tubes array within my data

Solution

script

data() {
        return {
            types: []
        }
    },
    methods: {
        handleChange (val) {
            axios.get(`/api/admin/getFromTubes/${val}`)
            .then(res => {
                this.types = res.data.data.tubes;
            })
            .catch(error => {
                console.log(error);
            })
        }
    }
    

template

<el-form-item label="Old Core">
        <el-select style="width: 100%;" filterable clearable v-model="form.old_core_id" placeholder="Select Old Core">
            <el-option
            v-for="cable in types"
            :key="cable.id"
            :label="cable.name"
            :value="cable.id">
                <span style="float: left">
                    {{ cable.name }}
                </span>
            </el-option>
        </el-select>
    </el-form-item>
    

Inquiry

Any suggestions on how to properly display the tubes array in the select dropdown template?

Answer №1

Shouldn't the code look like this for handling changes:

handleChange (val) {
    fetch(`/api/admin/getFromTubes/${val}`)
    .then(response => response.json())
    .then(data => {
        this.types = data[0].tubes;
    })
    .catch(error => {
        console.log(error);
    })
}

or perhaps it should be:

this.types = res.data.data[0].tubes;

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

Here is a way to trigger a function when a select option is changed, passing the selected option as a parameter to the function

Is there a way to call a function with specific parameters when the value of a select element changes in Angular? <div class="col-sm-6 col-md-4"> <label class="mobileNumberLabel " for="mobilrNumber">Select Service</label> <div cla ...

The Navbar is throwing a TypeError because it is unable to retrieve the property 'classList' of null

I am currently experimenting with building a navbar in HTML that has the capability to dynamically switch pages without changing links using href. The method I'm employing to achieve this involves adding a classList of is-active to the div elements wi ...

From AJAX response to React state attribute, store the JSON data

I have a component where I need to fetch freight values via ajax and store them in the state property of this class. import React, { Component } from 'react'; import Freight from './Freight'; import CreateFreightEntryModal from '. ...

Managing multiple sockets within a Vue application

Currently, my Vue application utilizes Vue-native-socket to communicate with a single socket. However, I now require the ability for my app to monitor multiple sockets simultaneously. Unfortunately, the documentation for Vue-native-socket does not provide ...

Using NodeJS with the Express framework to send a GET request

Can express be used as a client-module for making http-requests to another server? Currently, I'm handling requests like this: var req = http.get({host, path}, function(res) { res.on('data', function(chunk) { .... } } This ...

Seamless social login integration for registering with Stormpath

Transitioning from C# and PHP to Node.js has presented some challenges, especially when working with the Stormpath API. I am currently trying to integrate social login on the registration page, but the pre-built option only allows it on the Login page. Al ...

The content remains constant when navigating within the same view

Vuejs3 Composition API Route File: Below is the route configuration for SingleBoard.vue, which displays content based on passed props: const routes = [ { path: "/singleboard/:dbName/:dbMethod/:securityType/:alertType", name: & ...

The variable 'form' has not been assigned an initial value in the constructor of the property

Below is the snippet from my component.ts file: import { Component, OnInit } from '@angular/core'; import { Validators, FormControl, FormGroup, FormBuilder } from '@angular/forms'; @Component({ selector: 'app-license', te ...

Display the item request form whenever a selection of an unidentified item is made using select2

I want to implement select2 for a company search feature. In case the desired company is not available in the existing dataset, I need to provide an option for users to request adding the company data. This is the HTML code: <head> <link href=& ...

Utilizing VUE to transfer JSON data from a click event to an HTML template

I have recently started learning Vue and I am looking to pass the fetched data from a successful API call, which is in JSON format, to the HTML variable {{info}}. When I use the console.log(info), it displays the correct JSON content. Also, when utilizing ...

Issue encountered during compilation: EPERM: Unable to locate "vite import glob" (scandir operation not authorized)

Encountering an error when attempting to build my app for production using npm rum build. Error vite v3.0.7 building for production... ✓ 29 modules transformed. [vite:import-glob] EPERM: operation not permitted, scandir 'C:\Documents and Settin ...

How to send two different types of data using jQuery/AJAX to a .php file? (Syntax)

I am completely new to the world of jQuery/AJAX and I could really use some guidance. Here is the code snippet in question: $(function () { $('.button').on('click', function (event) { event.preventDefault(); //prevents ...

"Want to learn how to dynamically disable an input field in AngularJS when another field is selected? Find out how to achieve this using the

Hey there, I'm dealing with two input fields. Input field A is a drop-down menu and input field B. They both have the same value (same ng-model). My goal is to clear the second input field whenever the user selects an option from the dropdown. Can any ...

Guide to adding a URL link to an image tag in Vuetify and Nuxt.js

Hello! I am currently navigating the world of Nuxt.js and Vuetify, and I have a question about adding URL links to image tags. Essentially, I want users to be able to click on an image and be directed to another page via a designated link. About My Page L ...

Encountering a "Cannot GET" error when utilizing mongoose

Details of my router.js file: const express = require("express") const Note = require("../models/nodeModel") const router = express.Router() router.route("/notes").get((req, res) => { Note.find({ show_day: "2020-9-10" }) .then(foundNotes ...

Guide on retrieving the ID after a new entry is added using a trigger in Express.js and MySQL

Currently, I am utilizing express and workbench to set up a database for handling the creation, viewing, and updating of cars. When I make a POST request to add a new car, it generates a new entry with details such as manufacturer, model, and price. I hav ...

The socket.on() function is not able to receive any data

I am encountering an issue with implementing socket.on functionality $('#showmsg').click(function() { var socket = io.connect('http://localhost:3000'); var msgText = $('#msgtext'); socket.emit('show msg', msgText.va ...

What is the best way to access the child component in React?

const navArr = [ { path: "/introduction", title: "회사소개", subTitle: [{ title: "summary" }, { title: "vision" }], }, ] {navArr.map((obj) => { return ( <NavItem> ...

Generating a unique serial ID using Angular/JS

I am in the process of developing a function that will create a unique serial id by replacing a string with the format; xxxx-xxxx-xxxx-xxxx. The desired outcome is a serial like this: ABCD-1234-EFGH-5678, where the first and third parts consist of letters ...

Encountering a issue when trying to click the Menu icon in a Vue 3 admin template

i recently set up the CoreUI Vue admin template CoreUI Vue Template. Everything seems to be working smoothly, except for the menu icon https://i.stack.imgur.com/tOShL.png. Whenever I try to hide the side bar (which is a built-in feature), it's not fu ...