每个单词的首字母大写

Mad*_*rth 0 javascript vue.js nuxt.js

我试图在Nuxt.js中页面标题的每个单词的大写字母大写。我当前的代码将第一个单词的大写,但是我也需要用大写的形式将其余的大写。

  head() {
    return {
      title: this.$route.params.models.charAt(0).toUpperCase() + this.$route.params.models.slice(1).split('-').join(' ') + ' | ' + this.title,
      meta: [
        { hid: 'description', name: 'description', content: '' }
      ]
    }
  }
Run Code Online (Sandbox Code Playgroud)

我将如何处理?

Sat*_*hak 5

更新-

如果您仍然需要执行此操作的方法,请尝试此regex模式

function capitalize(value){
      return value.replace(/(?:^|\s|-)\S/g, x => x.toUpperCase());
}
 
 console.log(capitalize('hello i misunderstood your requirement initially by skipping the whole description'))
Run Code Online (Sandbox Code Playgroud)