Detailed explanation of Vue filters

Detailed explanation of Vue filters

insert image description here

<body>
    <div id="root">
        <h2>Display formatted time</h2>
        <!-- Computed property implementation -->
        <h2>It is {{fmtTime}}</h2>
        <!-- Methods implementation -->
        <h2>Now is {{getFmtTime()}}</h2>
        <!-- Filter time implementation-->
        <h2>It is {{time | timeFormater}}</h2>
    </div>
    <div id="root2">
        <h2>Now: {{msg |mySlice }}</h2>
    </div>
    <script>
        Vue.config.productionTip = false;
        //Global filter Vue.filter('mySlice', function(value) {
            return value.slice(0, 4)
        })
        new Vue({
            el: "#root",
            data: {
                time: 1637047951556 //timestamp},
            computed: {
                fmtTime() {
                    return dayjs(this.time).format('YYYY year MM month DD HH:mm:ss')
                }
            },
            methods: {
                getFmtTime() {
                    return dayjs(this.time).format('YYYY year MM month DD HH:mm:ss')
                }
            },
            filters:
                timeFormater(value) {
                    return dayjs(value).format('YYYY year MM month DD HH: mm: ss ')
                }
            },
        })

        new Vue({
            el: "#root2",
            data: {
                msg: 'hello world'
            }
        })
    </script>
</body>

insert image description here

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Do you really understand Vue's filters?
  • How much do you know about Vue.js filters?
  • Vue global filter concepts, precautions and basic usage methods
  • What you need to know about filters in Vue
  • Detailed explanation of filter instance code in Vue
  • Vue filter usage example analysis
  • Use of filters in Vue2.0 series
  • Tutorial on using filters in vue.js
  • Usage of filters in Vue

<<:  Solution to prevent caching in pages

>>:  How to Completely Clean Your Docker Data

Recommend

MySQL backup and recovery design ideas

background First, let me explain the background. ...

Differentiate between null value and empty character ('') in MySQL

In daily development, database addition, deletion...

A brief analysis of the difference between ref and toRef in Vue3

1. ref is copied, the view will be updated If you...

How to avoid data loop conflicts when MySQL is configured with dual masters

I wonder if you have ever thought about this ques...

Installation steps of docker-ce on Raspberry Pi 4b ubuntu19 server

The Raspberry Pi model is 4b, 1G RAM. The system ...

Steps for installing MySQL 8.0.16 on Windows and solutions to errors

1. Introduction: I think the changes after mysql8...

win10 mysql 5.6.35 winx64 free installation version configuration tutorial

mysql 5.6.35 winx64 free installation version con...

Linux Disk Quota Management Graphical Example

Disk quota is the storage limit of a specified di...

Docker installs redis 5.0.7 and mounts external configuration and data issues

Redis is an open source NoSQL database written in...

CSS realizes the layout method of fixed left and adaptive right

1. Floating layout 1. Let the fixed width div flo...

How to recover accidentally deleted messages files in Linux

If there are files that are being used by a proce...

Example of implementing dynamic verification code on a page using JavaScript

introduction: Nowadays, many dynamic verification...