Home > Article > Web Front-end > What is the usage of indexof in vue
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)”.
The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer. The indexof
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.
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!