Home  >  Q&A  >  body text

Classes with string literals in Vue, HTML

I want when I press the button to log in with a wrong password, the UI will show multiple alert popups instead of one because the user doesn't know if they still entered the wrong password.

So I use counter and string literal like this

<!-- mt = margin-top, so each alert won't lie on each other -->
<v-alert
  v-for="i in counter"
  :key="i"
  class=`mt-${i}` 
>
  Wrong Password
</v-alert>

This doesn't work. Any other ideas?

P粉938936304P粉938936304240 days ago289

reply all(2)I'll reply

  • P粉506963842

    P粉5069638422024-02-22 10:10:13

    You can bind classes -> :class="'mt-${i}'" tildas ` should only be around ${i} and around the whole name 'mt-yourcode' Use apostrophe

    reply
    0
  • P粉576184933

    P粉5761849332024-02-22 09:58:32

    This should work:

    
      Wrong Password
    
    

    View this example

    reply
    0
  • Cancelreply