Skip to content

Instantly share code, notes, and snippets.

@bosz
Created February 16, 2021 07:44
Show Gist options
  • Save bosz/728ca083814f8951421dfc3519f86838 to your computer and use it in GitHub Desktop.
Save bosz/728ca083814f8951421dfc3519f86838 to your computer and use it in GitHub Desktop.
Learning Vue JS 3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Learning Vue JS</title>
</head>
<body>
<div id="main">
<h1>Welcome to my vue tutorial</h1>
<div id="counter">
Counter: {{ counter }}
</div>
<div id="bind-attribute">
<span v-bind:title="message">
Hover your mouse over me for a few seconds to see my dynamically bound
title!
</span>
<p>Message is : {{ message }} </p>
</div>
<button v-on:click="reverseMessage">Reverse Message</button>
<input v-model="message" />
<h3>Conditions</h3>
<div id="conditional-rendering">
<button @click="toggleSeen">Toggle seen</button>
<span v-if="seen">Now you see me</span>
</div>
<h3>LIST</h3>
<div id="list-rendering">
<ol>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ol>
</div>
<div>
<h4>List from sub component</h4>
<todo-item
v-for="todo in todos"
v-bind:todo="todo"
v-bind:key="todo.id"
>
</todo-item>
</div>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script src="./index.js"></script>
</body>
</html>
const ComponentsApp = {
data() {
return {
counter: 0,
message: 'You loaded this page on ' + new Date().toLocaleString(),
seen: true,
todos: [
{ text: 'Learn JavaScript' },
{ text: 'Learn Vue' },
{ text: 'Build something awesome' }
]
}
},
mounted() {
setInterval(() => {
this.counter++
}, 1000)
},
methods: {
reverseMessage() {
this.message = this.message
.split('')
.reverse()
.join('')
},
toggleSeen() {
this.seen = !this.seen;
}
}
}
const app = Vue.createApp(ComponentsApp)
app.component('todo-item', {
props: ['todo'],
template: `<li>{{ todo.text }}</li>`
})
app.mount('#main')
// Vue.createApp(ComponentsApp).mount('#main')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment