Gather all information for populating the dropdown menu

I'm trying to fetch data from an API using Vue Form and Axios, but I'm having trouble retrieving it at the moment. I might have missed something. Specifically, I need to retrieve the brand of a car. When a brand is selected in one dropdown, the series list in another dropdown should change based on the selected brand. Can you please help me with this?

Here's the Vue.js code:

<div class="form-group">
  <label>Brand</label>
  <select class="select-dropdown-no-search form-control" v-model="brand" @change="listSeries()" name="brand" id="brand">
<option value="">--Select--</option>
<option v-for='data in brands' :value='data.BrandId'>{{ data.BrandName }}</option>
</select>
</div>

<div class="col-sm-6">
  <div class="form-group">
    <label>Series</label>
    <select class="select-dropdown-no-search form-control" v-model="series" @change="listCylinders()" name="series" id="series">
<option value="">--Select--</option>
<option v-for='data in series' :value='data.BrandId'>{{ data.BrandName }}</option>
</select>
  </div>
</div>

And here's the Vue.js code:

import axios from 'axios';
import API from '../API';

var urlAddStock = API.url.host + '/addstock';
var urlBrandList = API.url.host + '/brand';
var urlSeriesList = API.url.host + '/series';
var urlCylinderList = API.url.host + '/cylinder';
var urlTypeList = API.url.host + '/type';

//Vue.component('v-select', VueSelect.VueSelect);
var inputMobile = {
  init: function() {
    this.vueConfig();
    API.auth();
  },
  vueConfig: function() {
    var app = new Vue({
      el: '#app',
      data: {
        stockSubmit: false,

        brand: "",
        brands: [],

        series: "",
        series: [],
        access_token: ""
      },
      methods: {
        submitStock: function() {
          let self = this;
          this.stockSubmit = true;
          axios({
            method: 'post',
            url: urlAddStock,
            data: {
              BrandId: this.brand,
              brand: "",
              SeriesId: this.series,
              series: "",

              access_token: localStorage.getItem("token")
            }
          }).then(res => {
            console.log(res.data);

            if (res.data.message === "Data Added Successfully") {
              self.stockSubmit = false;
            } else {
              self.stockSubmit = false;
            }

          }, err => {
            console.log(err);
            self.stockSubmit = false;
          });
        },
        listBrand: function() {
          let self = this;
          axios({
            method: 'post',
            url: urlBrandList,
            data: {
              itemid: 6,
              access_token: localStorage.getItem("token")
            }
          }).then(response => {
            console.log(response.data);
            if (response.data.message === "Data Fetched Successfully") {
              this.brands = response.data;

            }

          }, err => {
            console.log(err);

          });

        },
        listSeries: function() {
          let self = this;
          axios({
            method: 'post',
            url: urlSeriesList,
            data: {
              brandId: this.brand,
              access_token: localStorage.getItem("token")
            }
          }).then(res => {
            console.log(res.data);
            if (res.data.message === "Data Fetched Successfully") {
              this.series = response.data;
            }

          }, err => {
            console.log(err);

          });

        }
      }
    })
  }
}

Answer №1

To update the Array reference in this.series, consider making the following modification:

if(res.data.message === "Berhasil Mengambil Data Seri"){
  // Assign a new array reference using the spread operator
  this.series = [...response.data];
} 

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

Error: Unable to set reference. The initial argument includes an undefined value in the 'gender' property of 'Users.ji8A7TkSldfdvieDqGxko9eV3Jy1'

I followed along with a Firebase Web Tutorial on YouTube about adding data to Firebase Database for an account settings tutorial. However, when I tried to implement the code provided, it didn't work. Can anyone offer any assistance? // Code snippet fo ...

PHP file not receiving data when using JavaScript Ajax with a 'post' request and URL

Could you assist me with a problem I am facing? I need help passing variable length HTML or any data to a PHP file via POST using JavaScript AJAX. I want to utilize vanilla JavaScript for my project as I want to gain more experience with it. While jQuery ...

MVC4: Exploring the Strategy for Handling Nested Ajax Requests

Creating a form in a web application, I implemented filtering data based on user selection using AJAX to retrieve JSON nested data from BankPlans table. However, I encountered an issue when attempting to fetch all required documents for each bankID from an ...

Definition for TypeScript for an individual JavaScript document

I am currently attempting to integrate an Ionic2 app within a Movilizer HTML5 view. To facilitate communication between the Movilizer container client and the Ionic2 app, it is crucial to incorporate a plugins/Movilizer.js file. The functionality of this f ...

How to manually remove an Angular directive

Is it possible to manually remove a directive? For instance, if I need the directive to perform a task once and then be cleared from memory. @Directive({ selector: '[doSomething]' }) export class DoSomethingDirective { constructor(private ...

Ways to increase the date by one month in this scenario

I am facing an issue with manipulating two date variables. One of the dates is set to last Friday by default, and I am attempting to add a month to this date using the code snippet below. However, it does not produce the desired result. var StartDate = ne ...

Error is being returned by the JSONP callback

Looking to grasp JSONP. Based on my online research, I've gathered that it involves invoking a function with a callback. Other than that, is the way data is handled and the data format similar to JSON? I'm experimenting with JSONP as shown below ...

Failure to specify the variable type can lead to the creation of automatic global variables

Recently, I stumbled upon this http://www.w3schools.com/js/js_scope.asp page which introduced me to the concept of "Automatic Global variables". Here is an example of how it works: // You can use carName variable here function myFunction() { carName ...

Encountering problem while opening a PDF document in an AngularJS mobile application built with Cordova

Currently I am working on implementing the functionality to open PDF documents in AngularJS on desktop and mobile devices. I have been referring to the following resource: Open a PDF in a new window of the browser with AngularJS I have implemented a simila ...

Passing image source from parent component to child component in Vue.js

I encountered an issue where I stored the image file name in a variable within the parent component and passed it to the child component using props. However, despite this setup, the child element is not displaying the image as expected. Here is the data ...

What are some strategies for reducing the data transmitted by clients over a websocket connection?

Currently, I am utilizing the ws module and I have a need to restrict the data sent by clients over websocket to 1Mb. By setting this limit, it will deter any potential malicious users from inundating the server with large amounts of data (GB scale), poten ...

Problem with repetitive looping of Jquery click event within an Angular controller

Currently, I am in the process of creating an app using onsen UI (angular based) + phonegap. One issue I am facing is related to a JQuery click event inside an angular controller. The problem arises when I navigate back through the page stack and then ret ...

Attempting to retrieve the current time using JavaSscript

const currentTime = new Date(); const hours = now.getHours(); Console.log(hours); This block of code is returning an error message... Uncaught ReferenceError: now is not defined Please note that this snippet is written in JavaScript. I attempted to us ...

Discovering the Method to Place a File into a Concealed Input Field Using Vue

I am currently in the process of previewing an image, and I want to find a way to return the file to my form for later submission on the backend. However, I am unsure of how to achieve this. Here is the code for my component: <template> <div> ...

Activate the class only on the current element

I need help with a specific functionality on my website. I have multiple sections with content and buttons, and when a button is clicked, I want to add an active class to the corresponding content section within the same row. <div id="1" class="row"> ...

Transition and transition-group animations in Vue.js do not seem to be functioning correctly

Having trouble implementing CSS transitions between slides in a Vue 2 Carousel component. Slides are created using v-for and shown/hidden using v-show. Attempted to use <transition> with mode=out-in, but encountered issues with two slides displaying ...

Is there something I'm overlooking, or is this behavior unusual for an "if statement"?

I am facing an issue with returning a value from a function. It seems like a simple task - just looping through my HTMLElements and returning the one I need. This problem is new to me, and I have spent a considerable amount of time debugging the code and ...

Encountering issues with integrating an external plugin with AngularJS code

For my app, I am attempting to incorporate intercom for monitoring user activity. It functions correctly when placed inside a script tag in index.html. However, I encounter an error when trying to use it in a .ts file as shown below: app/components/rocket/ ...

Error in Node.js Socket.io: The disconnect event is being triggered before the connect event

When the client reconnects after a network drop, the disconnect event is triggered on the server. Client code: var url ='192.168.1.101', port = '80', socket = io.connect('http://' + url + ':' + port, { &apo ...

Is there an improved guide available for using Netbeans' new language support plug-in?

Recently, I've started working with a new server side language that is based on Javascript. It has similar functionalities to PHP, but uses Javascript syntax for processing server responses and handling logic. In terms of text editors, Netbeans is my ...