-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_04.html
More file actions
58 lines (51 loc) · 2.06 KB
/
example_04.html
File metadata and controls
58 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<html>
<head>
<title>Vue.js Example 04</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="styles/site.css">
<script src="lib/vue@2.2.1.js"></script>
</head>
<body>
<div id="app">
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default" v-on:click="reverseGreeting">Reverse Greeting</button>
</div>
<input type="text" class="form-control" placeholder="Type your greeting..." v-model="message">
</div>
</div>
</div>
</div>
<script>
/**
Array, Objects, Fields are awesome !
But not enough ...
At some point we will need to interact with different HTML elements (eg: button).
Different HTML elements give us different events so we interact with them:
Buttons have a click event.
When we click a button we can run a function (eg: "doLogin", "removeItem" or even "reverseGreeting")
To link between an event and our function we use "v-on:[event name]", so in this case it is
"v-on:click" and we assign our function's name.
We declare our function under the methods section.
*/
var app = new Vue({
el: '#app',
methods: {
reverseGreeting: function () {
var reverseMsg = this.message.split('').reverse().join('');
alert(reverseMsg);
}
}
});
</script>
</body>
</html>
<!--
Example 04:
Make 3 different kind of Greetings:
- Reverse
- Uppercase
- Appending Hello to the beginning
-->