let template = `<h1>今天买了一个{{thing}},好{{mood}}<h1>`;
console.log(template.replace(/\{\{(\w+)\}\}/g,function(a,b,c){
return data[b];
}))
输出结果为:
<h1>今天买了一个华为手机,好开心<h1>
let template = `<h1>今天买了一个{{thing}},好{{mood}}<h1>`;
console.log(template.replace(/\{\{(\w+)\}\}/g,function(a,b,c){
return data[b];
}))
输出结果为:
<h1>今天买了一个华为手机,好开心<h1>