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

cannot add style on vue.js etemplate using a function

I’m trying to generate the text of a style tah usign a function in vue.js

<template>

        <div class="col-md-3" :style="setColor(c.percentage, c.blocked)">
       
</template>

<script>
export default {
  name: "",
  methods:{
    setColor(percentage,blocked){
      let opacity = (percentage / 100).toFixed(2);
      let color = '145,223,150';
      if(blocked){
        opacity = 0.6;
        color = '234,59,37'
      }else{
        if(opacity>0){
          if(opacity < 0.1){
            opacity = 0.1;
          }
          color = '145,223,150'
        }else{
          opacity = 1;
          color = '255,255,255';
        }
      }
      return `rgba(${color},${opacity})`;
    }
  }
}
</script>

<style scoped>

</style>

but it generates that code

<div class="col-md-3" style=""></div>

I don’t know what is wrong , do I missed something?First time on vue and I have a lot to learn xD

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

>Solution :

From the method you should return an object that has color or background-color as property and rgba(${color},${opacity})`; as value :

return {color:`rgba(${color},${opacity})`};
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