current position:Home>Vue data proxy and hijacking in front end

Vue data proxy and hijacking in front end

2022-04-29 05:12:02A little rabbit who likes eating radishes

Object.defineProperty()

Object.defineProperty() Method will be directly on an object Definition A new attribute , perhaps modify Existing properties of an object , And return this object .

Object.defineProperty(object, prop, descriptor);
 Parameters :  object , attribute ( String type ),{getter and setter}

Used for bidirectional binding of data and object properties .

    let num;
    let person = {
    
      name: ' Zhang San ',
      sex: ' male ',
    }

    Object.defineProperty(person, 'age', {
    
      get() {
    
        return num;
      },
      set(val) {
    
        num = val;
      }
    })

What is a data broker

Attributes in another object are represented by an object proxy ( read / Write ) operation .

adopt obj2 change obj1 Properties of :

    let obj1 = {
    
      x: 100,
    }
    let obj2 = {
    
      y: 500,
    }

    Object.defineProperty(obj2, 'x', {
    
      get() {
    
        return obj1.x;
      },
      set(val) {
    
        obj1.x = val;
      }
    })

Vue Data brokers in

Here vm amount to What is a data broker Medium obj2.
 Insert picture description here

 Insert picture description here

The data was hijacked

 Insert picture description here

Next section : Front end vue Event handling

copyright notice
author[A little rabbit who likes eating radishes],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/116/202204261123446529.html

Random recommended