Skip to content

Instantly share code, notes, and snippets.

@donvito
Created May 27, 2018 13:07
Show Gist options
  • Save donvito/d4c0d23e8a34a3488bcce26faca71b71 to your computer and use it in GitHub Desktop.
Save donvito/d4c0d23e8a34a3488bcce26faca71b71 to your computer and use it in GitHub Desktop.
VueJS getting started
<script src="https://unpkg.com/vue"></script>
<div id="app">
<p>{{ message }}</p>
<span v-bind:title="message2">
Hover your mouse over me for a few seconds
to see my dynamically bound title!
</span>
</div>
<div id="app2">
<ol>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ol>
</div>
<div id="app-7">
<ol>
<!--
Now we provide each todo-item with the todo object
it's representing, so that its content can be dynamic.
We also need to provide each component with a "key",
which will be explained later.
-->
<todo-item
v-for="item in groceryList"
v-bind:t="item"
v-bind:key="item.id">
</todo-item>
</ol>
</div>
<script>
new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!',
message2: 'You loaded this page on ' + new Date().toLocaleString()
}
})
new Vue({
el: '#app2',
data: {
todos: [
{ text: 'Learn JavaScript' },
{ text: 'Learn Vue' },
{ text: 'Build something awesome' }
]
}
})
Vue.component('todo-item', {
props: ['t'],
template: '<li>{{ t.text }}</li>'
})
var app7 = new Vue({
el: '#app-7',
data: {
groceryList: [
{ id: 0, text: 'Vegetables' },
{ id: 1, text: 'Cheese' },
{ id: 2, text: 'Whatever else humans are supposed to eat' }
]
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment