Skip to content

Instantly share code, notes, and snippets.

@zfedoran
Created May 2, 2016 18:24
Show Gist options
  • Save zfedoran/0c8d0c06d72263ec562aef7360c28a6f to your computer and use it in GitHub Desktop.
Save zfedoran/0c8d0c06d72263ec562aef7360c28a6f to your computer and use it in GitHub Desktop.
Simple Vue.js Example (no build tools)
<!-- Live Example: https://jsfiddle.net/Lqn6ocqm/ -->
<component>
<style>
.zelimir div {
background: #0ff;
}
</style>
<template>
<div class="zelimir">
<div>Zelimir Says: {{ number }} </div>
</div>
</template>
<script>
var el = document.currentScript;
Vue.component('zelimir', {
data: function() {
return {
number: Math.random()
}
},
created: function() {
},
template: el.parentElement.querySelector('template')
});
</script>
</component>
<component>
<style>
.joost div {
background: #eee;
}
</style>
<template>
<div class="joost">
<div>Joost Says: {{ time }} </div>
<zelimir v-for="v in [1,2,3,4]"></zelimir>
</div>
</template>
<script>
var el = document.currentScript;
Vue.component('joost', {
data: function() {
return {
time: new Date()
}
},
created: function() {
var self = this;
setInterval(function() {
self.time = new Date();
}, 100);
},
template: el.parentElement.querySelector('template')
});
</script>
</component>
<div id="app">
<joost></joost>
</div>
<script>
new Vue({
el: '#app'
});
</script>
@zfedoran
Copy link
Author

zfedoran commented May 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment