0

Can anyone explain why this is happening? New to Vue, and don't understand what's wrong?

This works:

<template>
    <div>
        ...
        <div v-else>
            {{ remaining.hours > 0 ? (remaining.hours < 10 ? '0' : '') + remaining.hours + ':' : '' }}

However when I try to add a span, I get the 'unclosed string literal' error:

<template>
    <div>
        ...
        <div v-else>
            {{ remaining.hours > 0 ? (remaining.hours < 10 ? '0' : '') + remaining.hours + '<span class="colon">:</span>' : '' }}
2
  • Can you create a jsfiddle or codepen example to reproduce the error ? Commented Apr 5, 2020 at 18:22
  • 1
    double quote inside single quote is not allowed. use back tick instead. {{ remaining.hours > 0 ? (remaining.hours < 10 ? '0' : '') + remaining.hours + `<span class="colon">:</span>` : '' }} or use escape before double quote {{ remaining.hours > 0 ? (remaining.hours < 10 ? '0' : '') + remaining.hours + '<span class=\"colon\">:</span>' : '' }} Commented Apr 5, 2020 at 18:55

1 Answer 1

1

The curly brackets interpret the data as plain text. For HTML use the v-html directive:

<div v-else v-html="remainingHtml">
computed : {
  remainingHtml () {
    return remaining.hours > 0 ? (remaining.hours < 10 ? '0' : '') + remaining.hours + '<span class="colon">:</span>' : '' :
  }
}

https://v2.vuejs.org/v2/guide/syntax.html

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.