|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>welcome to nano</title> |
| 6 | + </head> |
| 7 | + <body> |
| 8 | + <div id="app"></div> |
| 9 | + |
| 10 | + <script type="text/javascript"> |
| 11 | + const startTime = Date.now() |
| 12 | + </script> |
| 13 | + <script type="text/javascript" src="../dist/eve.js"></script> |
| 14 | + <script type="text/javascript"> |
| 15 | + ` |
| 16 | + {#if !helper[ a + b ](v)} |
| 17 | + <slot name="title"></slot> |
| 18 | +
|
| 19 | + { v + 1 && k ? '' : helper( helper( v ) ) } |
| 20 | +
|
| 21 | + <div> |
| 22 | + abc |
| 23 | + {#inc content } |
| 24 | + def |
| 25 | + </div> |
| 26 | +
|
| 27 | + <div @click="{ onClick($e) }"></div> |
| 28 | + {/if} |
| 29 | +
|
| 30 | + { a[ 1 + b * 2 ].b && c + 1 } |
| 31 | + {#if !helper[ a + b ](v)}{/if} |
| 32 | + { v + 1 && k ? '' : helper( helper( v ) ) } |
| 33 | + `; |
| 34 | + |
| 35 | + ` |
| 36 | + <a @click.prevent="{ onClick($e) }">{ isString( v ) ? v + 1 : 'hello' }</a> |
| 37 | + <input :value="{ v }" @keyup.enter="{ onEnter() }" /> |
| 38 | +
|
| 39 | + {#if v[b.c].length > 5} |
| 40 | + 文字长度不能超过5 |
| 41 | + {/if} |
| 42 | +
|
| 43 | + {#each items + 1 as item} |
| 44 | + { item + 1 } |
| 45 | + {/each} |
| 46 | +
|
| 47 | + {#if b} |
| 48 | + <div>1</div> |
| 49 | + <div>2</div> |
| 50 | + {#else} |
| 51 | + <div>3</div> |
| 52 | + <div>4</div> |
| 53 | + {/if} |
| 54 | + `; |
| 55 | + |
| 56 | + const Button = Eve.extend( { |
| 57 | + template: ` |
| 58 | + <button @click="{ this.onClick() }">{ text }</button> |
| 59 | + `, |
| 60 | + |
| 61 | + data() { |
| 62 | + return { |
| 63 | + text: '按钮文字' |
| 64 | + } |
| 65 | + }, |
| 66 | + |
| 67 | + methods: { |
| 68 | + onClick() { |
| 69 | + console.log( 'clicked' ) |
| 70 | + } |
| 71 | + } |
| 72 | + } ) |
| 73 | + |
| 74 | + const App = Eve.extend( { |
| 75 | + components: { |
| 76 | + Button |
| 77 | + }, |
| 78 | + |
| 79 | + data() { |
| 80 | + return { |
| 81 | + abc: 'class-abc', |
| 82 | + first: 'first', |
| 83 | + last: 'last', |
| 84 | + |
| 85 | + items: [1,2,3], |
| 86 | + a: 1, |
| 87 | + b: false, |
| 88 | + } |
| 89 | + }, |
| 90 | + computed: { |
| 91 | + fullname() { |
| 92 | + return this.data.first + ' ' + this.data.last |
| 93 | + } |
| 94 | + }, |
| 95 | + |
| 96 | + template: |
| 97 | + ` |
| 98 | + <div class="clazz { abc }" style="margin-top: 100px;" disabled a> |
| 99 | + <Button text="123"></Button> |
| 100 | +
|
| 101 | + {#each items as b} |
| 102 | + --- |
| 103 | + <div @click="{ console.log( this ),this.onClick($e, 'a', b) }">a</div> |
| 104 | + { b + 1 } |
| 105 | + <div>{ this.postfix( b, 'haha' ) + '~' }</div> |
| 106 | + { this.postfix( fullname, ' en?' ) } |
| 107 | + <br /> |
| 108 | + --- |
| 109 | + <br /> |
| 110 | + {/each} |
| 111 | +
|
| 112 | + {#if b} |
| 113 | + <div>b is true</div> |
| 114 | + {#else} |
| 115 | + <div>b is false</div> |
| 116 | + {/if} |
| 117 | + </div> |
| 118 | + ` |
| 119 | + , |
| 120 | + |
| 121 | + methods: { |
| 122 | + isString( v ) { |
| 123 | + return typeof v === 'string' |
| 124 | + }, |
| 125 | + |
| 126 | + postfix( value, v ) { |
| 127 | + return value + v |
| 128 | + }, |
| 129 | + |
| 130 | + onClick( e, v1, v2 ) { |
| 131 | + console.log( 'clicked', e, v1, v2 ) |
| 132 | + }, |
| 133 | + |
| 134 | + onEnter() { |
| 135 | + console.log( 'entered' ); |
| 136 | + } |
| 137 | + }, |
| 138 | + |
| 139 | + // 实例被创建 |
| 140 | + created() { |
| 141 | + console.log( 'I am created' ); |
| 142 | + this.$watch( 'first', ( v1, v2 ) => { |
| 143 | + this.data.full = this.data.first + this.data.last |
| 144 | + console.log( `first is changed from ${ v2 } to ${ v1 }` ); |
| 145 | + } ) |
| 146 | + this.$watch( 'last', ( v1, v2 ) => { |
| 147 | + this.data.full = this.data.first + this.data.last |
| 148 | + console.log( `last is changed from ${ v2 } to ${ v1 }` ); |
| 149 | + } ) |
| 150 | + this.$watch( 'full', ( v1, v2 ) => { |
| 151 | + console.log( `full is changed from ${ v2 } to ${ v1 }` ); |
| 152 | + } ) |
| 153 | + this.$watch( 'fullname', ( v1, v2 ) => { |
| 154 | + console.log( `fullname is changed from ${ v2 } to ${ v1 }` ); |
| 155 | + } ) |
| 156 | + |
| 157 | + this.data.first = 'first2' |
| 158 | + this.data.last = 'last2' |
| 159 | + |
| 160 | + setTimeout( () => { |
| 161 | + this.data.first = 'first3' |
| 162 | + this.$update() |
| 163 | + }, 1000); |
| 164 | + |
| 165 | + setTimeout( () => { |
| 166 | + this.data.items = [ 6, 7, 8 ] |
| 167 | + this.$update() |
| 168 | + }, 2000); |
| 169 | + }, |
| 170 | + |
| 171 | + // 被挂载到dom中 |
| 172 | + attached() { |
| 173 | + console.log( 'I am attached' ); |
| 174 | + }, |
| 175 | + |
| 176 | + // 从dom中脱离 |
| 177 | + detached() { |
| 178 | + console.log( 'I am detached' ); |
| 179 | + }, |
| 180 | + |
| 181 | + // 被销毁 |
| 182 | + disposed() { |
| 183 | + console.log( 'I am disposed' ); |
| 184 | + }, |
| 185 | + } ); |
| 186 | + |
| 187 | + console.log( '---\nApp' ); |
| 188 | + console.dir( App ); |
| 189 | + console.log( '---' ); |
| 190 | + |
| 191 | + const app = new App(); |
| 192 | + |
| 193 | + console.log( '---\napp' ); |
| 194 | + console.log( app ); |
| 195 | + console.log( '---' ); |
| 196 | + |
| 197 | + app.$mount( '#app' ); |
| 198 | + |
| 199 | + // console.log( 'Sub ->' ); |
| 200 | + // |
| 201 | + // const SubApp = App.extend( { |
| 202 | + // components: { A: () => {} } |
| 203 | + // } ) |
| 204 | + // SubApp.component( 'B', () => {} ) |
| 205 | + // App.component( 'C', () => {} ) |
| 206 | + // new SubApp() |
| 207 | + </script> |
| 208 | + </body> |
| 209 | +</html> |
0 commit comments