Sample code for create Vue.js Component
Last active
February 3, 2017 21:25
-
-
Save tps2015gh/db6acfadcec83a05bb7aa8555fd01188 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.component('row1', { | |
template: '<div class="ro1" >A custom component!</div>' | |
}) | |
var data = {counter : 0 } | |
new Vue({ | |
el: '#app', | |
data: { | |
i: 1, | |
message: 'Hello Vue.js!', | |
}, | |
components: { | |
'local1': { | |
props: ['tx'], | |
template: '<div class="lo1" v-on:click="increment" > lo1: i={{tx}} counter={{counter}} </div>' | |
,data : function(){ | |
return {counter : 0 } | |
} | |
,methods: { | |
increment: function() { | |
this.counter += 1 /* this component local */ | |
this.$emit('increment') | |
} | |
} | |
} | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/vue/dist/vue.js"></script> | |
<link rel="stylesheet" type="text/css" href="theme.css"> | |
<div id="app"> | |
<p>{{ message }}</p> | |
<row1> | |
<</row1> | |
<table width="50%"> | |
<tr is="local1" tx="ABC "></tr> | |
<tr is="local1" :tx="i"></tr> | |
<tr is="local1" :tx="i+1"></tr> | |
<tr is="local1" :tx="i+2"></tr> | |
<tr is="local1" :tx="i+3"></tr> | |
<tr is="local1" :tx="i+4"></tr> | |
</table> | |
</div> | |
<!-- code must run below HTML --> | |
<script src="app.js"></script> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.lo1 { | |
border: 1px solid silver; | |
background-color: lightyellow; | |
padding-left: 5px; | |
pointer: hand; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment