Adjusting values in Vue.js with a slider bar

Just starting out with vue.js and wanted to create a slide-bar with min and max values.

I came across vue range slider, installed it, and successfully implemented it.

The issue I'm facing is changing the value on the slider. The values from my API request are in an array:

[400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000]
. However, the max value on the slider needs to be a number, not an array.

I searched through the documentation for information on how to change this max value, but unfortunately found nothing :/ You can see what my slide bar currently looks like here .

I want to replace the values with those provided in the array.

HTML
         .box_slider 
                  VueSlideBar(v-model="value"
                  :min="0"
                  :max="sliderAmount" //this is my value
                  :processStyle="slider.processStyle"
                  :lineHeight="slider.lineHeight"
                  :tooltipStyles="{ backgroundColor: 'red', borderColor: 
                  'red' }"
                  class="demo-demo" id="slider-1")

 VUE.JS
      <script>
      import co from "@/util/co.js";
      import VueSlideBar from "vue-slide-bar";
       var sliderAmount;
     export default {
       name: "Repaid",
     components: {
      VueSlideBar
         },
        data() {
         return {
       slider: {
         lineHeight: 10
            },
            sliderAmount: undefined
         };
          },
        methods: {},
      mounted() {
          co.getLoanPriceList().then(data => {
          let dataLoan = data.data;
            console.log(dataLoan);
        this.sliderAmount = dataLoan.amounts;
         return this.sliderAmount;
          });
         },
         computed: {
           sliderAmountMap() {
          const sliderAmountValue = this.sliderAmount;
                 return sliderAmountValue; //this is my value
         console.log(sliderAmountValue);
           }
       }
        };
         </script>

If anyone has worked on a similar slider, any help in getting started would be greatly appreciated.

EDIT

Thank you all for your suggestions and time. The solution was to add slider.data to the VueSlideBar component, and create a variable data with an array in the data section.

HTML

     .box_slider {{sliderAmountMap}}
                  VueSlideBar(v-model="value"
                  :min="0"
                  :data="slider.data"
                  :max="sliderAmount"
                  :processStyle="slider.processStyle"
                  :lineHeight="slider.lineHeight"
                  :tooltipStyles="{ backgroundColor: 'red', borderColor: 
                   'red' }"
                  class="demo-demo" id="slider-1")

VUE.JS

 export default {
   name: "Repaid",
    components: {
     VueSlideBar
   },
     data() {
      return {
       slider: {
       lineHeight: 10,
       data: [400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 
       3000]
       },
       sliderAmount: undefined
      };
     },

Answer №1

By iterating over the array, each value is assigned to the maximum properties of the slider:

     .box_slider (v-for="(item,index) in sliderAmount" v-bind:key="index")
              VueSlideBar(v-model="value"
              :min="0"
              :max="item" //assigning value here
              :processStyle="slider.processStyle"
              :lineHeight="slider.lineHeight"
              :tooltipStyles="{ backgroundColor: 'red', borderColor: 
              'red' }"
              class="demo-demo" id="slider-1") 

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

What are the steps to create custom Typescript RecursiveOmit and RecursivePick declarations for efficient cloning routines?

For some time now, I have been attempting to create a declaration for RecursiveOmit and RecursivePick in cloning methods such as JSON.parse(JSON.stringify(obj, ['myProperty'])) type RecursiveKey<T> = T extends object ? keyof T | RecursiveKe ...

Next.js is having trouble identifying the module '@types/react'

Every time I attempt to launch my Next.js app using npm run dev, an error notification pops up indicating that the necessary packages for running Next with Typescript are missing: To resolve this issue, kindly install @types/react by executing: np ...

Implement the geocomplete feature following an ajax event

When I click a button, it adds an input box for entering an address. To assist with auto-completion of the address, I'm using the geocomplete plugin. However, I've noticed that the geocomplete functionality only works on input boxes generated wit ...

Issue with AngularJS binding not updating when the initial value is null and then changed

I am encountering an issue with my binding not updating, and I have a hypothesis on why it's occurring, but I'm unsure about how to resolve it. Within my controller, there is a company object that includes a property called user, which may or ma ...

Execute and generate a continuous loop in JavaScript

I successfully implemented an image slider using pure PHP, but encountered issues when integrating it into Yii framework. The images were not loading due to the following reasons: - JavaScript block was not loading image numbers. - I am unsure how to load ...

Is it possible to verify whether a Node Js query is empty or not?

I've been attempting to determine if a result query is empty or not, conducting thorough research in the process. Below is the code illustrating the query I'm executing and the two methods I employed to check if it's empty. The issue at han ...

Tips for modifying navbar appearance as user scrolls?

I am currently working on a website using Bootstrap 4. The goal is to create a navbar with a transparent background that transitions to white smoothly when the user scrolls down. I want the navbar to return to its initial state when the user scrolls back u ...

Trouble with Displaying Angular Template using ng-hide

I am encountering an issue with my angular directive that is used to display a button form. The template remains hidden until it needs to be displayed for the user. Although the template works fine on its own, it does not appear when integrated into the la ...

jquery module for retrieving and updating messages

I want to develop a custom plugin that can be utilized in a manner similar to the following example. This isn't exactly how I plan to use it, but it serves as the initial test for me to fully grasp its functionality. HTML: <div id="myDiv">< ...

Is it possible to retrieve JSON data and display only the entries with positive values in an HTML

I am working on a project that involves fetching JSON API data and displaying it in an HTML table, but only for values above 10. Below is the code snippet along with my JavaScript. I specifically want to exclude negative values and only display positive v ...

Leverage AJAX for real-time Django Model updates

Seeking insights on how to effortlessly update a Django model through AJAX without reloading the page or requiring user input for saving. Various tutorials address fetching data from Django models using AJAX, yet resources on updating models remain scarce. ...

Utilize ng-show/ng-hide to dynamically display messages or content based on the results obtained

One of my functions builds and returns a JSON object like this: {"message":"No Grupos de MetaDetalles found","entities":[],"breadcrumbs":[],"parent_id":0} Now, I have an Angular view set up like this: <table id="example-datatables" class="table table ...

What is the procedure for controlling a Textfield in the Browser with a Java code?

I have an automation problem that I am trying to solve. The task involves accessing a specific webpage with two editable text fields and some other elements, extracting the content from these text fields using a Java program to filter keywords and generate ...

Setting a default value in ng-options can be accomplished by using the ng-init

One way to set a dropdown list with a default value in AngularJS is by using the following code: <select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init="repeatSelect = data[0].id"> <option ng-repeat="option in data" val ...

Incorporate communication between the front-end and backend

I encountered an error while attempting to import the getUser function in my backend code. The actual function is located in the frontend at ../utils/auth. How can I successfully import between front-end and backend? Or might there be another issue at pla ...

Storing information when an object is indexed in a for loop, to be retrieved later when

My JavaScript code includes an AJAX call that takes user input from a form and uses it to search for a JSON object. The matching objects are then displayed in a datalist successfully. Everything is working well so far, but now I want to extract specific f ...

Having trouble with Vue.js implementation of Bootstrap tab navigation?

I am currently working on a vue.js application that consists of 2 routed components. I recently attempted to integrate a bootstrap tab navigation into the first component, but unfortunately, the tab contents are not being properly displayed. <templat ...

What method can be used to retrieve previous values when validation fails in Laravel and Vue?

Currently, I am utilizing both laravel and vue in my project. The issue I am facing is with retrieving old values when validation fails due to the v-model used in the select box... <select id="role" name="role" class="form-contr ...

Sort array in ReactJS using JSON data fetched from a URL

There is a URL where I have stored some data, such as: [ {"id":1,"first_name":"add","last_name":"add"}, {"id":2,"first_name":"sfdf","last_name":"aad"} ...

What is the best way to extract URL query parameters and store them in a MySQL database using Node.js and Express

I am working on a project where I need to store specific information like names and widths from the URL query into my MySQL database. The format of the URL query should resemble this: /register?name=XXXX&width=###.### However, I seem to be facing ch ...