I want to dynamically attach an emoji image to the knob on a vue slider . I have tried doing this using css variables but it has not been successful. I have also tried the following link Vue.js dynamic <style> with variables but I am still not getting it to work.
I have installed 'vue-range-slider' and have imported RangeSlider
The range-slider is set up the following way.
<template>
<div id="slider_div" >
<range-slider
class="slider"
min="0"
max="100"
</range-slider>
</div>
</template>
<script>
import RangeSlider from 'vue-range-slider'
import 'vue-range-slider/dist/vue-range-slider.css';
export default {
name: 'susScore',
data: function() {
return {
emoji_data: "../assets/emoji_small.jpg",
}
},
components: {
RangeSlider
}
</script>
<style>
#slider_div{
margin-top: 95px;
margin-left: 4%;
}
.slider{
width:200px;
}
.range-slider-knob {
}
I can add an emoji by adding an emoji image to the knob. This is done by adding the following css either between or under the template tags.
<style >
:root {
--emoji_var: url("../assets/emoji_small.jpg");
}
</style>
and then in the range-slider-knob css class I also added: background-image: var(--emoji_var)
.range-slider-knob {
background-image: var(--emoji_var)
}
So far so good.
Though the problem arises when I want to add an image dynamically.
I tried doing this by changing the --emoji_var
variable to url('{{this.emoji_data}}')
as below:
<style >
:root {
--emoji_var: url('{{emoji_data}}');
}
</style>
Though this resulted in that the image would not show.
Question:
How can I dynamically get the values from the data option (emoji_data) in the susScore component into the css variable (emoji_var) ?
Thanks