将每个单词的首字母大写[重复]

问题描述 投票:0回答:1
我正在尝试在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: '' } ] } }

我将如何处理?
javascript vue.js nuxt.js
1个回答
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'))
© www.soinside.com 2019 - 2024. All rights reserved.