Review of Object.defineProperty method<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Review of Object.defineproperty method</title> </head> <body> <script type="text/javascript" > let number = 18 let person = { name:'Zhang San', sex:'male', } Object.defineProperty(person,'age',{ // value:18, // enumerable:true, //controls whether the property can be enumerated, the default value is false // writable:true, //controls whether the property can be modified, the default value is false // configurable: true //Controls whether the property can be deleted. The default value is false //When someone reads the age property of person, the get function (getter) will be called and the return value is the value of age get(){ console.log('Someone read the age property') return number }, //When someone modifies the age property of person, the setter function will be called and receive the modified value set(value){ console.log('Someone modified the age property, and the value is', value) number = value } }) // console.log(Object.keys(person)) console.log(person) </script> </body> </html> What is a data broker?
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>What is a data agent?</title> </head> <body> <!-- Data proxy: operation (read/write) of attributes in another object through an object proxy --> <script type="text/javascript" > let obj = {x:100} let obj2 = {y:200} Object.defineProperty(obj2,'x',{ get(){ return obj.x }, set(value){ obj.x = value } }) </script> </body> </html> Data Proxy in Vue<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Data Proxy in Vue</title> <!-- Import Vue --> <script type="text/javascript" src="../js/vue.js"></script> </head> <body> <!-- 1. Data proxy in Vue: Use the vm object to proxy the operation (read/write) of the attributes in the data object 2. Benefits of data proxy in Vue: More convenient operation of data in data 3. Basic principle: Add all properties in the data object to vm through Object.defineProperty(). For each property added to the vm, specify a getter/setter. Operate (read/write) the corresponding attributes in data inside the getter/setter. --> <!-- Prepare a container --> <div id="root"> <h2>School name: {{name}}</h2> <h2>School address: {{address}}</h2> </div> </body> <script type="text/javascript"> Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. const vm = new Vue({ el:'#root', data:{ name:'Shang Silicon Valley', address:'Hongfu Technology Park' } }) </script> </html> Basic use of events<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Data Proxy in Vue</title> <!-- Import Vue --> <script type="text/javascript" src="../js/vue.js"></script> </head> <body> <!-- 1. Data proxy in Vue: Use the vm object to proxy the operation (read/write) of the attributes in the data object 2. Benefits of data proxy in Vue: More convenient operation of data in data 3. Basic principle: Add all properties in the data object to vm through Object.defineProperty(). For each property added to the vm, specify a getter/setter. Operate (read/write) the corresponding attributes in data inside the getter/setter. --> <!-- Prepare a container --> <div id="root"> <h2>School name: {{name}}</h2> <h2>School address: {{address}}</h2> </div> </body> <script type="text/javascript"> Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. const vm = new Vue({ el:'#root', data:{ name:'Shang Silicon Valley', address:'Hongfu Technology Park' } }) </script> </html> Event modifiers<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Basic use of events</title> <!-- Import Vue --> <script type="text/javascript" src="../js/vue.js"></script> </head> <body> <!-- Basic use of events: 1. Use v-on:xxx or @xxx to bind the event, where xxx is the event name; 2. The event callback needs to be configured in the methods object and will eventually be on the vm; 3. Do not use arrow functions for functions configured in methods! Otherwise this is not vm; 4. The functions configured in methods are all functions managed by Vue, and this points to vm or component instance object; 5. @click="demo" and @click="demo($event)" have the same effect, but the latter can pass parameters; --> <!-- Prepare a container --> <div id="root"> <h2>Welcome to {{name}} study</h2> <!-- <button v-on:click="showInfo">Click me for info</button> --> <button @click="showInfo1">Click me for information 1 (no parameters)</button> <button @click="showInfo2($event,66)">Click me for prompt information 2 (parameter passing)</button> </div> </body> <script type="text/javascript"> Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. const vm = new Vue({ el:'#root', data:{ name:'Shang Silicon Valley', }, methods:{ showInfo1(event){ // console.log(event.target.innerText) // console.log(this) //This is vm alert('Hello, classmate!') }, showInfo2(event,number){ console.log(event,number) // console.log(event.target.innerText) // console.log(this) //This is vm alert('Hello classmate!!') } } }) </script> </html> Keyboard events<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Keyboard Events</title> <!-- Import Vue --> <script type="text/javascript" src="../js/vue.js"></script> </head> <body> <!-- 1. Commonly used button aliases in Vue: Enter => enter Delete => delete (captures "delete" and "backspace" keys) Exit => esc Space => space Line break => tab (special, must be used with keydown) Up => up down => down left => left Right => right 2. For buttons that Vue does not provide aliases, you can use the original key value of the button to bind, but be careful to convert it to kebab-case (short dash naming) 3. System modifier keys (special usage): ctrl, alt, shift, meta (1) Used with keyup: Press the modifier key, then press other keys, and then release the other keys, the event will be triggered. (2) Used with keydown: trigger events normally. 4. You can also use keyCode to specify specific keys (not recommended) 5.Vue.config.keyCodes.Custom key name = key code, you can customize the key alias --> <!-- Prepare a container --> <div id="root"> <h2>Welcome to {{name}} study</h2> <input type="text" placeholder="Press Enter to prompt input" @keydown.huiche="showInfo"> </div> </body> <script type="text/javascript"> Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. Vue.config.keyCodes.huiche = 13 // defines an alias key new Vue({ el:'#root', data:{ name:'Shang Silicon Valley' }, methods: { showInfo(e){ // console.log(e.key,e.keyCode) console.log(e.target.value) } }, }) </script> </html> SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to restore data using binlog in mysql5.7
>>: How to redraw Button as a circle in XAML
Using the internal function instr in MySQL can re...
This article shares the specific code of Vue to i...
background As the company's sub-projects incr...
one. wget https://dev.mysql.com/get/mysql57-commu...
Table of contents Overview 1. Download via URL 2....
1. Introduction Elasticsearch is very popular now...
There are too much knowledge to learn recently, a...
<br />This is from the content of Web front-...
Table of contents 1. Definition and Use 1.1 Defin...
Open any web page: for example, http://www.baidu....
1. Vue--The first vue-cli program The development...
Table of contents Some basic instructions 1. Chec...
Create docker-compose.yml and fill in the followi...
Feelings: I am a backend developer. Sometimes when...
Note: Since .NET FrameWork cannot be run in core ...