Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vue 3 multiple values in range slider

I have a range slider with 3 steps, each step is supposed to give me a different image resolution; ie 512×512 or 1024×1024.

I’ve set up the slider but I’m unable to figure out how to get the width and height values that I’ve set up in the data()

data() {
    return {
        resolution: [
            {id: 1, width: 512, height: 512},
            {id: 2, width: 816, height: 816},
            {id: 3, width: 1024, height: 1024},
      ]
    }
}

HTML

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<input type="range" 
       class="form-range" 
       id="customRange1" 
       v-model="resolution" 
       min="1" max="3" step="1"
>
{{ resolution.width }}

>Solution :

Please take a look at following snippet:

const app = Vue.createApp({
  data() {
    return {
      resolution: [
        {id: 1, width: 512, height: 512},
        {id: 2, width: 816, height: 816},
        {id: 3, width: 1024, height: 1024},
      ],
      currentRes: 1
    };
  },
  computed: {
    currentResolution() {
      return this.resolution.find(r => r.id === +this.currentRes)
    }
  }
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
  <input type="range" 
       class="form-range" 
       id="customRange1" 
       v-model="currentRes"
       :min="1" :max="resolution.length" step="1"
  >
  {{ currentResolution.width }}
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading