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

Detailed explanation of the use of Vue filters filters

php中世界最好的语言
Release: 2018-04-13 14:10:29
Original
3176 people have browsed it

This time I will bring you a detailed explanation of the use of Vuefiltersfilters, and what are the notes when using Vue filters. Here are actual cases, let’s take a look.

Sample code

Use vue single file component and use moment plug-in to format date

<template>
 <p>
  <h1>{{date | dateFormat}}</h1> 
 </p>
</template>
<script>
 import moment from 'moment';
 import 'moment/locale/zh-cn';
 moment.locale('zh-cn');
 export default {
  data() {
   return {
    date: new Date()
   }
  },
  filters: {
   dateFormat(val) {
    return moment(val).calendar();
   }
  }
 }
</script>
Copy after login

Instructions

There is no this reference in the filter. This inside the filter is undefined, so do not try to use this to refer to the variable or method of the component instance in the filter.

ps: Let’s take a look at the basic usage of Vue filters

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

Or

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

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to traverse and display collection data in Angular

How to use mint-ui with vue.js Carousel component

The above is the detailed content of Detailed explanation of the use of Vue filters filters. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!