JavaScript is a scripting language that belongs to the web! JavaScript is used by millions of web pages to improve design, validate forms, detect browsers, create cookies, and more. JavaScript is the most popular scripting language on the Internet.
In the past few years, the front-end technology stack has been developing too quickly. From the previous frameworks for dom operations such as jquery, ext.js and other frameworks, the current transition to the current mvvm mode has enabled front-end developers to gradually distract their attention from dom operations. Focusing on the realization of logic, personally think that the development efficiency has at least doubled. One core of the mvvm model is the two-way binding of data.
The above is the application of data bidirectional binding in the vue framework, personally think this feature is very good, is the key to greatly improve the development efficiency, then if you leave the mvvm framework, I also want to achieve this data two-way binding, or not Can be achieved, how to achieve it?
Bidirectional binding with native js simulation dataImplementation steps:
One: use js to listen to changes in data and synchronize the changed data to the page from time to time.
In order to implement this function we need to use a method of js Object.defineProperty
Recommend my front-end group, there will be dry goods sharing from time to time, beginners also have a set of well-organized introductory tutorials, welcome beginners and advanced partners.
1. Property introduction
2. Method introduction
Probably introduces the two methods of the defineProperty core. As you can see here, you can use these two built-in methods to do things. See below for an example of using this method to implement data bidirectional binding.
The effect is as follows: when the name changes, the values ​​in the following input boxes also change synchronously:
Multi function remote manual pulse generator for control of all axes.
Manual Sensor,Miniature Optical Kit Encoder,Rotary Encoder With Led Ring,Optical Quadrature Encoder
Yuheng Optics Co., Ltd.(Changchun) , https://www.yhenoptics.com