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

ES Lint Error When Passing Parameter to Method in Vue

I have an ES Lint Parsing Error in my Vue page. This is occurring because my parameter I am passing to the method contains a "." symbol.

Error - Syntax Error: Unexpected token (1:1628)

<div class="text-sm font-medium" v-bind:class="{ highlight(coin.price_change_percentage_24h) }">

What is the solution to this syntax? Is there a way to escape this in the template file?

Full code can be found here

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

Thanks in advance for any help!

>Solution :

Define highlight as a computed property which returns a function that takes the price as parameter :


    computed:{
      highlight(){
        return (priceChange)=>{
        if(priceChange < 0)
        {
          return 'text-red-900'
        }
        if(priceChange > 0)
        {
          return 'text-green-900'
        }
        return '';
       }
      }
    },

and bind it to the class without using {} :

<div class="..." v-bind:class="highlight(coin.price_change_percentage_24h)">

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