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

An example Analysis of vue2.0 responsive programming

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "vue2.0 responsive programming case analysis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Vue2.0 uses Object.defineProterty to traverse and convert attributes in data to getter and setter, and in getter a collection is made using the context of the data, which we call dependency collection.

In setter, the operation of dependency update will be triggered, so that there may be multiple changes in the template according to the dependency, so we collect all the places and perform a batch operation while waiting for the update.

Here is a demonstration of demo

(function () {

Let x

Let y

Let f = n = > n * 100 + 200

Let active

Let onXChanged = function (cb) {

Active = cb

Active ()

Active = null

}

/ / collect more dependencies

Class Dep {

/ / dependency collection, adding response dependencies to deps

Constructor () {

This.deps = new Set ()

}

Depend () {

If (active) {

This.deps.add (active)

}

}

/ / one pair depends on one execution in the current deps

Notify () {

This.deps.forEach (dep = > dep ())

}

}

Let ref = initValue = > {

Let value = initValue

Let dep = new Dep ()

Return Object.defineProperty ({}, "value", {

Get () {

Dep.depend ()

Return value

}

Set (newValue) {

Value = newValue

Dep.notify ()

}

})

}

X = ref (1)

OnXChanged () = > {

Y = f (x.value)

Console.log (y)

});

X.value = 2

X.value = 3

) ()

This is the end of the content of "vue2.0 responsive programming example Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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