js查找字符串中某个字符出现的位置及次数

//this.$route.path = "/bottomPage/modeSettings/basicInformation";当前路由
//this.activeUrl = undefined
var index = this.$route.path.indexOf("/");
var num = 0;
var urlIndex = undefined;
while (index !== -1) {
  // console.log("/出现的位置是" + index);
  num++;
  if (num == 3) {
    urlIndex = index;
  }
  index = this.$route.path.indexOf("/", index + 1);
}
if (num > 2) {
  var url = this.$route.path;
  this.activeUrl = url.slice(0, urlIndex);
  // console.log(this.activeUrl);
} else {
  this.activeUrl = this.$route.path;
  // console.log(this.activeUrl);
}

你可能感兴趣的:(vue,JavaScript,javascript,vue.js,css,es6,html)