0

This works:

<span v-if="name">
    Hi there, {{ name }}
</span>

... but it forces me to use span for the whole text, I just want it on the name variable. In handlebars for example I could do:

{{#if name}}
    Hi there, <span>{{ name }}</span>
{{/if}}
1
  • You could replace/wrap span with template. demo Commented Feb 15, 2018 at 1:02

1 Answer 1

5

You can use a template for that.

we can use v-if on a <template> element, which serves as an invisible wrapper. The final rendered result will not include the <template> element.

For example:

<template v-if="name">
  Hi there, <span>{{ name }}</span>
</template>
Sign up to request clarification or add additional context in comments.

Comments

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.