模版字符串
用法:
使用反引号` ` 包起来的字符串
可以使用${}拼接字符串,在${}里面可以继续嵌套模板字符串,也可以使用方法
const xiaoming = {
name: 'xiaoming',
age: 14,
say1: function() {
console.log('我叫' + this.name.toUpperCase() + ', 我今年' + this.age + '岁!');
},
say2: function() {
console.log(`我叫${ `Mr.${ this.name.toUpperCase() }` }, 我今年${ this.age }岁!`);
}
}
xiaoming.say1();
xiaoming.say2();
场景:模拟去服务器拿数据,其实是返回对象,渲染出一个列表
const getImoocCourseList = function() {
// ajax
return {
status: true,
msg: '获取成功',
data: [{
id: 1,
title: 'Vue 入门',
date: 'xxxx-01-09'
}, {
id: 2,
title: 'ES6 入门',
date: 'xxxx-01-10'
}, {
id: 3,
title: 'React入门',
date: 'xxxx-01-11'
}]
}
};
//通过数据库得到数据并将其写入网页
const {