简体   繁体   English

使用Vue2 JS这个基本的计算数据值有什么问题?

[英]What is wrong with this basic computed data value using Vue2 JS?

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? https://screenshots.firefox.com/pDElTgV9EB58BjbS/127.0.0.1我做错了什么?

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>
    `
}) 

The JS template literal uses backticks and not single quotes. JS模板文字使用反引号而不是单引号。

computed: {
    bobbyFullName() {
        return `${this.bobby.first} ${this.bobby.last}`;
    },
    johnFullName() {
        return `${this.john.first} ${this.john.last}`;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM