我在某些地方看到,为了从 props 中获取 title 的值,我们使用
{`${props.title} `}
而在其他一些地方,我们使用它
{props.title}
有什么区别?
最佳答案
第一个选项是使用模板文字,进一步阅读 here来自文档:
Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.
第二个选项只是将字符串值传递给属性。
考虑以下因素:
const data = {
title: 'random title'
};
console.log(data.title);
console.log(`${data.title}`);
希望对您有所帮助!
关于javascript - {`${props.title} ` } 和 {props.title} 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59812833/