3

I have followed a tutorial online that uses computed data to output the first name and last name. My code is the same, but the rendered result is different. Presently, it is seeing what is after the $ as just a string and not the assigned data. https://screenshots.firefox.com/pDElTgV9EB58BjbS/127.0.0.1 What am I doing wrong?

const app = new Vue({
    el: "#app",
    data: {
        bobby: {
            first: "Bobby",
            last: "Boone",
            age: 25
        },
        john: {
            first: "John",
            last: "Boone",
            age: 35,
        }
    },
    computed: {
        bobbyFullName() {
            return '${this.bobby.first} ${this.bobby.last}'
        },
        johnFullName() {
            return '${this.john.first} ${this.john.last}'
        }
    },
    template: `
    <div>
        <h1>Name: {{bobbyFullName}}</h1>
        <p>Age {{bobby.age}}</p>

        <h1>Name: {{johnFullName}}</h1>
        <p>Age {{john.age}}</p>

    </div>
    `
}) 

1 Answer 1

3

The JS template literal uses backticks and not single quotes.

computed: {
    bobbyFullName() {
        return `${this.bobby.first} ${this.bobby.last}`;
    },
    johnFullName() {
        return `${this.john.first} ${this.john.last}`;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

So the return part needs to use ` and not '. You need eyes of a hawk to see that youtu.be/h6lhOYv-QM4?t=108
Exactly, otherwise it's gonna be treated as normal strings.

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.