Vue custom instructions configured modifiers and mass participation

And II, please refer https://www.cnblogs.com/zui-ai-java/p/11109213.html 

 

Three, index.html

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 7     <title>index</title>
 8     <style>
 9         .card{
10             width:200px;
11             padding:10px;
12             margin:5px;
13             background: #ccc;
14         }
15     </style>
16 
17 </head>
18 <body>
19     <div id="app">
20         <div v-pin:true.bottom.left="card1.pinned"class = "Card" > 
21              < the Button @click = "card1.pinned =! card1.pinned" > fixed / Cancel </ the Button > 
22              clicks Buddha ah happen to fall in love with each other Dali local marble and consequently if Jing'an Temple
 23          </ div > 
24  
25          < div V-PIN = "card2.pinned" class = "Card" > 
26 is              < A @click = "card2.pinned =! card2.pinned" the href = "#" > PIN IT </ A >
27              Master Lu Buddha Rafah beans love crazy hair Stephen Rafah
 28          </div > 
29  
30          < div > 
31 is                  the basis of embodiment
 32                  new new a Vue instance < br > 
33 is                  registered component and use < br > 
34 is                  registered assembly
 35                  global registration < br > 
36                  parts Sign < br > 
37 [                  Create Vue instance by new, global registration component, three component parts Sign frequency (scene) < br > 
38 is                  the props in the data stream Vue
 39                  the props manner value < br> 
40                  written in the props hump nomenclature is why in HTML (template) and use dashes nomenclature? < Br > 
41 is                  the necessity of using the v-bind: props under the premise of not binding, as can only be parsed string < br > 
42 is                  Vue custom event
 43                  from the principles defined event < br > 
44 is                  custom events effect 1-- "redefines" event listener mechanism range < br > 
45                  effect custom events 2 - such that the assembly Sons clear responsibility < br > 
46 is                  used in slot < br > 
47                  named slot < br > 
48                  
49         
50                  text < br > 
51          
52                  Top < br > 
53                  Vue two basic ways to render < br > 
54                  new new instance of a Vue
 55                  that we typically use to mount the root node in the initialization: < br > 
56 is          
57 is                  new new Vue ({ < br > 
58                  EL: '#app' < br > 
59                  }) < br > 
60                  
61 is          
62 is                  registered and used components< Br > 
63 is                  by Vue.component () to register a component, you can use it globally, embodied in each of the new Vue
 64          
65                  < br > Example / registration component, the template attributes or corresponding option DOM template, to be used directly < br > 
66          
67                  
68          
69                  top < br > 
70                  registration component
 71                  global registration < br > 
72                  which, for example, on the example of using the new Vue created: < br > 
73 is          
74                  copy the code
 75                  Vue.component ( 'My-Component', { <br > 
76                  Template: ' < P > I was registered in the global assembly </ P > ' < br > 
77                  })
 78                  / *
 79                  Vue.component (Component Name [String] Component Object) < br > 
80                  * /
 81          
82                  new new Vue ({ < br > 
83                  EL: '#app', < br > 
84                  Template: ' < My-Component > </my-component>'<br>
85                 })
86                 复制代码<br>
87                 
88         
89                 demo:<br>
90         </div>
91     </div>
92    
93     <script src="../lib/vue.js"></script>
94     <script src="./js/main.js"></script>
95 </body>
</96 html>

 

Four, main.js

 

1  // custom instruction v-pin 
2  // EL element tag indicates the instruction is located 
. 3  // Binding mean instructions, wherein the instructions to obtain the value attribute value 
. 4 Vue.directive ( "PIN", function (EL, Binding) {
 . 5      var = pinned binding.value;
 . 6      // the console.log ( "pinned", pinned) 
. 7  
. 8  // use property modifiers can be instructed properties, js is a target 
. 9      var position = binding.modifiers;
 10      // the console.log ( "position", position); 
. 11  // use arg property to get the specified parameters 
12 is      var warning = binding.arg;
 13 is      //the console.log ( "warning", warning); 
14      IF (pinned) {
 15          el.style.position = "Fixed" ;
 16  // by the position object traversing the for..in .. 
. 17          for ( var Key in position) {
 18              // use [key], dynamically set orientation 
. 19              el.style [Key] = "40px" ;
 20 is          }
 21 is  
22 is          IF (warning) {
 23 is              el.style.background = "Yellow" ;
 24          }
 25          // = el.style.top "40px"; 
26          // el.style.left = "40px";
27     }else{
28         el.style.position = "static";
29         el.style.background = "#ccc"
30     }
31 
32 })
33 
34 new Vue({
35     el:"#app",
36     data:{
37         card1:{
38             pinned:false
39         },
40         card2:{
41             pinned:false
42         }
43     }
44 })

 

 

 

 

Fifth, the effect

 

 

Six, Thanks for watching, if in doubt, welcome exchange oh

 

Guess you like

Origin www.cnblogs.com/zui-ai-java/p/11110568.html