Created
March 6, 2019 14:20
-
-
Save wiput1999/1f52fdf5abb312f717574ab8dc980486 to your computer and use it in GitHub Desktop.
Vue Tutorial 06/03/2019
This file contains 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
<!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