Skip to content

Instantly share code, notes, and snippets.

@wiput1999
Created March 6, 2019 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiput1999/1f52fdf5abb312f717574ab8dc980486 to your computer and use it in GitHub Desktop.
Save wiput1999/1f52fdf5abb312f717574ab8dc980486 to your computer and use it in GitHub Desktop.
Vue Tutorial 06/03/2019
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue</title>
</head>
<body>
<div id="app">
{{ message }}
<br />
{{ reversedMessage }}
<div @click="setText" v-if="show" v-bind:class="activeClass">
Show if show is true
</div>
<div v-else>Show if show is false</div>
<text-area v-bind:hello="112"></text-area>
<input type="text" v-model.lazy="name" />
<a v-bind:href="url" v-bind:style="fontSizeComputed">Facebook</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.8/dist/vue.js"></script>
<script>
Vue.component('text-area', {
props: ['hello'],
template: '<p>{{hello}}</p>'
})
let app = new Vue({
el: '#app',
data: {
activeClass: 'active',
name: '',
url: 'https://fb.com/wiput.pootong',
message: 'Hello Vue!',
show: true,
object: {message: 'lel'},
isActive: true
},
methods: {
setText: function() {
this.message = 'Prayuth'
}
},
watch: {
name: function() {
this.message = 'asdfg'
}
},
computed: {
fontSizeComputed: function() {
return {
color: 'red',
fontSize: 13 + this.name.length + 'px'
}
},
reversedMessage: function() {
return this.name
.split('')
.reverse()
.join('')
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment