0

I want when I press button log in with wrong password, the UI show multiple alert popup instead of one because the user will not know whether they still enter wrong pass or not.

So I using 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>

It doesn't work. Any other ideas?

1
  • 1
    I really do not understand your use case but in any case the string literals are JavaScript feature. To tell Vue that what is passed into a prop/class/style should be interpreted as JavaScript, use v-bind - v-bind:class="`mt-${i}`" Commented Oct 19, 2021 at 14:21

2 Answers 2

5

This should work:

<v-alert
  v-for="i in counter"
  :key="i"
  :class="`mt-${i}`" 
>
  Wrong Password
</v-alert>

See this example

Sign up to request clarification or add additional context in comments.

2 Comments

Almost close, need v-bind
Yes, ofc ;) thanks! It was in the example.
0

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

5 Comments

The :class part is correct, but your explanation of how to use string literals is not (it should be :class=`mt-${i}`)
still seems like " " should be wrapped around the class though
Nope. That would just make it a normal string containing literal backticks, and without the variable substitution.
Aaaaand it turns out I'm wrong; vue templates do require surrounding quotes around a string literal. Weird but true. Apologies for the misinformation!
thanks! i knew i wasnt crazy! haha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.