Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Vue snooping properties and calculation properties

Shulou Source: shulou.com Published: 2022-06-02 07:03:35 10月03日 Update

This article mainly explains how to use Vue snooping attributes and computational attributes. The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Vue snooping attributes and computational attributes.

1. Watch snooping attributes

This property is used to monitor a change in data and trigger the corresponding callback function execution.

Basic usage adds a watch attribute with a value of an object. The property name of the object is the data to be monitored, and the property value is the callback function, which is triggered whenever the corresponding value of the property name changes.

The callback function takes two parameters:

NewVal, the value after the data has changed.

OldVal, the value before the data is changed.

Counter:

Before the counter {{shu}} changes: after {{ov}} changes: {{nv}} plus a var vm = new Vue ({el:'# app', data: {shu:1, ov:0, nv:0}, methods: {}}) vm.$watch ("shu", function (nval,oval) {vm.$data.ov = oval vm.$data.nv = nval})

Add listening and assign the value before the counter change to the variable ov, and the changed value to the variable nv

Vm.$watch ("shu", function (nval,oval) {vm.$data.ov = oval vm.$data.nv = nval})

1.

1. Shopping Cart

Serial number, commodity name, commodity price, purchase quantity operation {{sp.id}} {{sp.money}}-{{sp.sum}} + reset total price: {{getmaney ()}} var vm = new Vue ({el:'# app' Data: {sps: [{id:1, name: "Apple 13", money:6000, sum:1}, {id:2, name: "Apple 12", money:5000, sum:1}, {id:3, name: "Apple 11", money:4000 Sum:1}]}, methods: {getmaney:function () {var masks 0 For (var xerox

Tags: Properties data monitoring functions methods objects apples counters learning monitoring content variables only at the same time goods that is time cache pages changes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi MySQL Microsoft Shulou Tech Info