Fork me on GitHub
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}",["你好", "世界"])
posted on 2019-04-16 09:37  lingfeng95  阅读(4000)  评论(0编辑  收藏  举报