Home > front end >  2. V - bind, v - on
2. V - bind, v - on

Time:10-06

1. V - bind to binding HTML attributes in the


Note: the class binding when multiple attributes with array & lt; H3: & gt; {{h3}} & lt;/h3 & gt;

And if use v - bind binding multiple class behind only the first effective invalid

(can be used in the ternary operator or & amp; & Or | |)

For example: & lt; H3: : & gt; {{h3}} & lt;/h3 & gt;

Unless the binding is valid & lt; H3: & gt; {{h3}} & lt;/h3 & gt;


Note: binding style can only be used when the object or array can not directly write up binding two style at the same time as the class

For example: & lt; H3: style="{color: aa}" & gt; {{h3}} & lt;/h3 & gt;



Note: if use object representation can set this property is used by using use the false is not true, also can add an array object combination of




Note: differential expression can't write on the attribute

For example: & lt; Img v - bind: SRC="https://bbs.csdn.net/topics/img" Alt="" & gt;

Can be abbreviated as: & lt; : img SRC="https://bbs.csdn.net/topics/img" Alt="" & gt;


2. V - on: listen event & lt; The button v - on: click="handleClick1" & gt; Click & lt;/button> Can be abbreviated as @


Note: to monitor the method must be on the object of the methods to

. Note: the console log (event), the event is the event object event. The target object of click

Note: $event said event object & lt; The button v - on: click="handleClick1 ($event, 2)" & gt; Click & lt;/button>


<script SRC="https://cdn.jsdelivr.net/npm/[email protected]" & gt; </script> <style> The red {color: red; Background - color: rgba (0, 0, 0, 0.2); }. Yellow {color: yellow; }. Black {color: RGB (173, 125, 125); }. Greed {color: green; }. Width {width: 300 px; }. Height {height: 200 px; } & lt;/style>
<script> Const vd=new Vue ({el: '# div' data: {img: './0272 ca245fe80ddd8a0f05aba56b8e97. JPG ', h3: 'hi! ', h3Color: 'red', h3Width: 'width', h3Height: 'height', h3True: true, h3False: false, aa: 'yellow', bb: { backgroundColor: 'black' }, h4ClassArr: ['greed', 'yellow', 'black'], h4Index: 0, count: 0, }, methods: { handleClick1() { console.log(event) console.log(event.target) this.h4Index=++this.count % 3; }}}); </script>



Note: & lt; Script SRC="https://cdn.jsdelivr.net/npm/[email protected]" & gt; </script> <style> The yellow {color: yellow; }. Black {color: RGB (173, 125, 125); }. Greed {color: green; } & lt;/style>
<script> Const vd=new Vue ({el: '# div' data: {h4ClassArr: [' greed ', 'yellow', 'black'], h4Index: 0, the count: 0,}, the methods: {handleClick1 (e) {//console log (e)==console. The log (event). The console log (e) enclosing h4Index=+ + this. Count % 3. }}}); </script>



Note: & lt; Script SRC="https://cdn.jsdelivr.net/npm/[email protected]" & gt; </script> <style> The yellow {color: yellow; }. Black {color: RGB (173, 125, 125); }. Greed {color: green; } & lt;/style>
<script> Const vd=new Vue ({el: '# div' data: {h4ClassArr: [' greed ', 'yellow', 'black'], h4Index: 0, the count: 0,}, the methods: {handleClick1 (e) {//if the above parameters e represents the console log (e) enclosing h4Index=+ + this. Count % 3. }}}); </script>



Note: & lt; Script SRC="https://cdn.jsdelivr.net/npm/[email protected]" & gt; </script> <style> The yellow {color: yellow; }. Black {color: RGB (173, 125, 125); }. Greed {color: green; } & lt;/style>
<script> Const vd=new Vue ({el: '# div' data: {h4ClassArr: [' greed ', 'yellow', 'black'], h4Index: 0, the count: 0,}, the methods: {handleClick1 (e, num) {//$event said event object. The console log (e) enclosing h4Index=+ + this. Count % 3. }}}); </script> nullnullnullnullnullnullnull
  • Related