Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Vue snooping properties and calculation properties

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report