Detailed explanation of Vue's methods and properties

Detailed explanation of Vue's methods and properties

Vue methods and properties

1. Methods

Usage 1

methods: {
Method name: function(){},
}

Usage 2

methods: {
method name(){}
}

Notice

{ {}}Call to write()

Example

{ {aa()}}

Event triggering

@click=aa" can have () or not. If you need to pass parameters, add ()
Passing the special parameter $event can get the event object

2. Computed properties

What are computed properties?

computed

Characteristics of computed properties

  1. Computed properties have cache
  2. Computed properties are cached based on their dependencies.
  3. Computed properties are only re-evaluated when their dependencies change.
  4. When the properties that the calculated property depends on change, it will be recalculated.

Methods in computed properties

set(da)
get()

Example

 	computed:{
                 //Calculated properties//Calculated properties are cached//Directly call {{}} without writing ()
                 //When the attribute that the calculated attribute depends on changes, it will recalculate once bb(){
                    return this.arr.filter(a=>a.indexOf(this.search) > -1)
                 },
                 cc:{
                     //When the calculated property is called, the get method is automatically triggered, and when the calculated property is modified, the set method is automatically triggered set(a){
                        console.log('I am set'+"received content"+a+"received content")
                     },
                     get(){
                        console.log('I am get')
                        return this.arr.filter(a=>a.indexOf(this.search) > -1)

                     }
                 }
            },

This is the end of this article about Vue's methods and property cases. For more information about Vue's methods and properties, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of calculated properties, monitoring properties and life cycle in Vue.js
  • Summary of the use of Vue computed properties and listeners
  • Computed properties and listening properties in Vue
  • Detailed explanation of Vue's calculated properties
  • Vue computed property code example
  • Vue calculation attributes + class and style binding in Vue (recommended)
  • Vue learning notes: calculation properties and listener usage
  • Solution to Vue's calculation property not being able to monitor changes within the array

<<:  CentOS 6 uses Docker to deploy redis master-slave database operation example

>>:  How to add fields and comments to a table in sql

Recommend

Analysis of examples of using anti-shake and throttling in Vue components

Be careful when listening for events that are tri...

How to write beautiful HTML code

What Beautiful HTML Code Looks Like How to write ...

js to achieve a simple carousel effect

This article shares the specific code of js to ac...

CentOS 6.4 MySQL 5.7.18 installation and configuration method graphic tutorial

The specific steps of installing mysql5.7.18 unde...

Summary of MySQL lock knowledge points

The concept of lock ①. Lock, in real life, is a t...

How to add custom system services to CentOS7 systemd

systemd: The service systemctl script of CentOS 7...

Centos7 startup process and Nginx startup configuration in Systemd

Centos7 startup process: 1.post(Power-On-Self-Tes...

Solution to span width not being determined in Firefox or IE

Copy code The code is as follows: <html xmlns=...

A brief discussion on the specific use of viewport in mobile terminals

Table of contents 1. Basic Concepts 1.1 Two kinds...

Getting Started Tutorial for Beginners ⑨: How to Build a Portal Website

Moreover, an article website built with a blog pro...

How to set process.env.NODE_ENV production environment mode

Before I start, let me emphasize that process.env...

Are you still Select *?

There are many reasons why an application is as s...

Introduction to building a DNS server under centos7

Table of contents 1. Project environment: 2: DNS ...

Graphic tutorial on installing CentOS7 on VMware 15.5

1. Create a new virtual machine in VMware 15.5 1....