Home > Web Front-end > JS Tutorial > body text

Detailed explanation of Vue filter usage

小云云
Release: 2018-01-22 10:33:38
Original
1697 people have browsed it

This article mainly introduces the introduction of Vue filter and its detailed usage. VueJs provides a powerful filter API that can perform various filtering processes on data. Let’s follow the editor to take a look, I hope it can help everyone.

VueJs provides a powerful filter API that can perform various filtering processes on data and return the required results

Basic usage of Vue filters


// 注册
Vue.filter('my-filter', function (value) {
 // 返回处理后的值
})
// getter,返回已注册的过滤器
var myFilter = Vue.filter('my-filter')
Copy after login


//在mustache中使用
{{ msg | uppercase }}
Copy after login

or


//在标签中使用
<input type="password" v-model="psw | validate">
Copy after login

Default filter

Note: Using the default filter has been deprecated in Vue 2.0 version

##NameFunctioncapitalizeFirst letter is capitalizeduppercaseAll capslowercaseAll lowercasecurrencyOutput money and decimal point##pluralizedebouncelimitByfilterByorderBy
Output plural form
Delayed execution function
in v Used in -for, limit the number
Used in v-for, select data
Used in v-for, sorting
Custom filter

Use a global definition of a filter

 //过滤非法字符
 Vue.filter(&#39;validate&#39;, function(val) {
  val = val.toString();
  reg = /[`~!@#$%^&*()_+<>?:"{},\/;&#39;]/im;

  if(reg.test(val)) {
   $.alert("请勿输入非法字符", "温馨提示");
   //返回时删除非法字符
   return val.substr(0, val.length - 1);
  } else {
   //原内容返回
   return val;
  }
 });
Copy after login

Have you learned how to use

<input type="password" placeholder="输入密码" v-model="psw | validate" maxlength = "18">
Copy after login

in the form? Collect it if you find it useful.

Related recommendations:

Detailed explanation of Ajax request and Filter cooperation case

Detailed explanation of CSS3 filter attribute

Detailed introduction to filter function in JavaScript

The above is the detailed content of Detailed explanation of Vue filter usage. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template