Leanote's Blog
I love Leanote!
Toggle navigation
Leanote's Blog
Home
Chrome
Git
Linux
Windows
Others
工具大全
VsCode
Expo
Html
JavaScript
Npm
Node
Mock
React-Native
React
TypeScript
小程序
插件
正则
Dva
Ant-Design-React
Umi
Vue
Vux
Ant-Design-Vue
Http
Java
flutter
开发小工具
About Me
Archives
Tags
动态路由path里截取name
2021-08-31 06:46:28
8
0
0
admin
``` function replaceReg(str) { return str.replace(/\s[a-z]/g, function ($1) { return $1.toLocaleUpperCase() }).replace(/^[a-z]/, function ($1) { return $1.toLocaleUpperCase() }) } let name = "" try { const file = require(`@/views${ route.path }.vue`) const componentName = file.default.name if (componentName) { name = componentName } else { throw Error("Fail: Don't Find 'name', src: '" + route.path + "'") } } catch (err) { // console.log(777777777, err) const nameArr = route.path.split("/") let setName = replaceReg(nameArr[nameArr.length - 1]) if (setName.length < 6 && nameArr[nameArr.length - 2]) { name = replaceReg(nameArr[nameArr.length - 2]) + setName } } ```
Pre:
gitbash - window下使用zip命令报错
Next:
vue-router使用笔记
0
likes
8
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.