Home >Web Front-end >Front-end Q&A >What is the usage of indexof in vue

What is the usage of indexof in vue

青灯夜游
青灯夜游Original
2021-12-27 14:41:357096browse

In vue, indexof() can be used to return the position where a specified string value first appears in the string. You can also use the return value to determine whether the specified string exists. The syntax "stringObject.indexOf( searchvalue,fromindex)”.

What is the usage of indexof in vue

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer. The indexof

indexOf() method in

vue returns the position where a specified string value first appears in the string.

Syntax

stringObject.indexOf(searchvalue,fromindex)

Parameter description

  • searchvalue: required. Specifies the string value to be retrieved.

  • fromindex: optional integer parameter. Specifies the position in the string to begin searching. Its legal values ​​are 0 to stringObject.length - 1. If this parameter is omitted, the search will start from the first character of the string.

Description

This method will retrieve the string stringObject from beginning to end to see if it contains the substring searchvalue. The starting position of the search is at the fromindex of the string or the beginning of the string (when fromindex is not specified). If a searchvalue is found, the position of the first occurrence of searchvalue is returned. Character positions in stringObject start from 0.

Tips and Notes

Note: The indexOf() method is case-sensitive!

Note: If the string value to be retrieved does not appear, this method returns -1.

Example

How to use indexOf() to retrieve within a string.

What is the usage of indexof in vue

if (whiteList.indexOf(to.path) !== -1) {undefined

// 在免登录白名单,直接进入

next()

} else {undefined

next(`/login?redirect=${undefinedto.path}`) // 否则全部重定向到登录页

NProgress.done()

}

}

[Related recommendation: "vue.js tutorial"]

The above is the detailed content of What is the usage of indexof in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn