如何在数据库中保存标记的模板文字

时间:2019-12-07 18:25:09

标签: javascript ecmascript-6 template-literals

function vehicle(strings, type) {
    var wheels= "no";
    if(type === "car"){ wheels = 4;} 
    else if(type === "cycle"){ wheels = 2;} 
    return `${strings[0]}${wheels}${strings[1]}`;
}

var type = "car";
var output = vehicle`This vehicle has ${type} wheels.`;
console.log(output); //This vehicle has 4 wheels.

在数据库中保存"vehicle`This vehicle has ${type} wheels.`"的最佳方法是什么?我可以进行一些字符串操作,但想知道更好的方法。

0 个答案:

没有答案