1

I want to replace some text from the string with link. I dont know how can I display it. SO far below code displays string with href link.

<span class="text">{{ $t(myText) }}</span>

    myText() {
        var text = "You can click text.";

        var href = "<a href='https://www.google.com'>Click Here</a>";

        var replaced = text.replace("click", href);

        return replaced;
    },
1
  • 2
    When you're using the handlebars syntax, the content will be inserted as plain text. You might want to use v-html instead, i.e. v-html="$t(myText)" Commented Jun 24, 2021 at 13:47

1 Answer 1

2

To elaborate on my comment: the handlebars/moustache syntax is used to insert plain text into your template. That means that any string that contains HTML will be inserted as-is without parsing it as DOM.

In order to insert HTML into your template, you will need to use the v-html directive, i.e.:

<span class="text" v-html="$t(myText)"></span>

However, note that this presents a security risk if you're allowing users to insert their own content into the element.

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

2 Comments

How can i open in new tab ?
target="_blank"

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.