Vue.prototype.$stringFormat = function stringFormat (formatted, args) { for (let i = 0; i < args.length; i++) { let regexp = new RegExp('\\{' + i + '\\}', 'gi') formatted = formatted.replace(regexp, args[i]) } return formatted }
仿照string.format("{0}-{1}","你好", "世界")
使用方法:
$stringFormat("{0}-{1}",["你好", "世界"])