当前位置:网站首页>14. Use of filter
14. Use of filter
2022-07-20 08:40:00 【Where the wind falls】
Definition : Format the data to be displayed before displaying it ( It is suitable for some simple logical processing )
grammar :
1. Registration filter :Vue.filter(name,callback) or new Vue{filters:{}}
2. Use filters :{ { xxx | Filter name }} or v-bind: attribute ="xxx | Filter name "
remarks : The filter can also receive additional parameters 、 Multiple filters can also be connected in series
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> filter </title>
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript" src="../js/dayjs.min.js"></script>
</head>
<body>
<!--
filter :
Definition : Format the data to be displayed before displaying it ( It is suitable for some simple logical processing ).
grammar :
1. Registration filter :Vue.filter(name,callback) or new Vue{filters:{}}
2. Use filters :{
{ xxx | Filter name }} or v-bind: attribute = "xxx | Filter name "
remarks :
1. The filter can also receive additional parameters 、 Multiple filters can also be connected in series
2. Did not change the original data , Is to generate new corresponding data
-->
<!-- Prepare a container -->
<div id="root">
<h2> Displays the formatted time </h2>
<!-- Calculate the property implementation -->
<h3> Now it is :{
{fmtTime}}</h3>
<!-- methods Realization -->
<h3> Now it is :{
{getFmtTime()}}</h3>
<!-- Filter implementation -->
<h3> Now it is :{
{time | timeFormater}}</h3>
<!-- Filter implementation ( The ginseng ) -->
<h3> Now it is :{
{time | timeFormater('YYYY_MM_DD') | mySlice}}</h3>
<h3 :x="msg | mySlice"> Silicon Valley </h3>
</div>
<div id="root2">
<h2>{
{msg | mySlice}}</h2>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false
// Global filter
Vue.filter('mySlice',function(value){
return value.slice(0,4)
})
new Vue({
el:'#root',
data:{
time:1621561377603, // Time stamp
msg:' Hello , Silicon Valley '
},
computed: {
fmtTime(){
return dayjs(this.time).format('YYYY year MM month DD Japan HH:mm:ss')
}
},
methods: {
getFmtTime(){
return dayjs(this.time).format('YYYY year MM month DD Japan HH:mm:ss')
}
},
// Local filter
filters:{
timeFormater(value,str='YYYY year MM month DD Japan HH:mm:ss'){
// console.log('@',value)
return dayjs(value).format(str)
}
}
})
new Vue({
el:'#root2',
data:{
msg:'hello,atguigu!'
}
})
</script>
</html>
边栏推荐
猜你喜欢
找免费录屏软件的过程-没想到win10自带这个功能
Pytorch target detection coco API explanation data generation
Chapter 62: blue screen crash when running vs program on win10
Recursive backtracking - maze walking
Function recursion in C program
更易上手的C语言入门级芝士 (3) 常见关键字+define+指针+结构体(超详细)
Heap sorting and heap related operations
C language custom types: structure, enumeration, union
[Nodejs]Nodejs创建一个简单的服务器
使用nvm use出现exit status 1与exit status 145乱码
随机推荐
学习日记4-程序结构和控制语句
淘宝flexible.js文件实现弹性布局
What is the difference between pointer array and array pointer?
二阶及N阶最长公共子序列
学习日记3-数据的输入输出
ES6之Object.defineProperty 和 Proxy 区别
59-[重点]Object.defineProperty的get方法
Standard IO and file IO
Pytorch target detection competition (I) data analysis
75-局部自定义指令——bind和update方法
【学习笔记】“STL演讲比赛流程管理系统”作业总结
Application of learning diary 5-c language function
4000 words, let you understand recursion and its example practice (C language, with pictures)
数塔问题及变形
My first blog
学习日记1
C language program environment and preprocessing
Easier to use C language entry-level cheese (1) data types, variables and constants, strings + escape characters + comments (super detailed)
更易上手的C语言入门级芝士 (1) 数据类型、变量和常量、字符串+转义字符+注释(超详细)
4. MVC model and MVVM model