In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use replace in vue. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In vue, replace is used to match the specified string and replace, or replace the record at the time of the jump, with the syntax of "str.replace (regexp/substr,replacement)" or "router.replace (location)".
This article operating environment: windows10 system, Vue2.9.6 version, DELL G3 computer.
What is the use of replace in vue
Vue.js source code replace method
/ * Camelize a hyphen-delimited string. * / var camelizeRE = /-(\ w) / g; var camelize = cached (function (str) {return str.replace (camelizeRE, function (_, c) {return c? C.toUpperCase ():';})}); / * Hyphenate a camelCase string. * / var hyphenateRE = /\ B ([Amurz]) / g; var hyphenate = cached (function (str) {return str.replace (hyphenateRE,'- $1') .toLowerCase ()}); syntax
Str.replace (regexp | substr, newSubStr | function)
Parameter regexp (pattern)
A RegExp object or its literal quantity. The content matched by the rule is replaced by the return value of the second parameter.
Substr (pattern)
A string to be replaced by newSubStr. It is treated as an entire string rather than a regular expression. Only the first match is replaced.
NewSubStr (replacement)
The string used to replace the matching part of the first parameter in the original string. Some special variable names can be interpolated in this string. Refer to the following using a string as a parameter.
Function (replacement)
A function used to create a new substring whose return value replaces the result matched by the first parameter. Refer to the following to specify a function as an argument.
Replace document View
The first camelize conversion method:
Replace specifies a function as an argument to view his output through the console
As you can see above, replace is implemented through global regular matching, similar to the lastIndex implementation of exex and test
The replace in the vue source code will match globally, and run the function body to replace newStr.
The second hyphenateRE transformation uses the special variable name $parameter
Description
This method does not change the string itself that calls it, but simply returns a new replaced string.
When doing a global search and replacement, the regular expression needs to include the g flag.
Use a string as a parameter
The replacement string can be inserted with the following special variable name:
The value $$represented by the variable name is inserted with a "$". $& insert a matching substring. Insert the content to the left of the current matching substring. Insert the content to the right of the currently matched substring. If the first argument is a RegExp object and n is a non-negative integer less than 100, insert the nth parenthesis matching string. Tip: the index starts at 1.
Eg:
Regular global matching non-word boundaries, where hyphens + uppercase letters are matched, and then-$1 global replacement
Thank you for reading! This is the end of the article on "how to use replace in vue". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.