-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaula-15-transferindo-comp-nao-parent.html
107 lines (81 loc) · 2.43 KB
/
aula-15-transferindo-comp-nao-parent.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<div id="app">
<h1>{{title}}</h1>
<br /> <br /> <br />
<div class="container">
<formulario></formulario>
<br />
<list></list>
</div>
</div>
<template id="formulario">
<div class="card">
<div class="card-block">
<div class="form-group">
<label for="">Titulo</label>
<input v-model="title" type="text" class="form-control">
</div>
<button @click.stop.prevent="submit()" class="btn btn-primary">Enviar</button>
</div>
</div>
</template>
<template id="list">
<ul class="list-group">
<li v-for="item in list" class="list-group-item">{{item.title}}</li>
</ul>
</template>
</body>
</html>
<script src="https://unpkg.com/vue"></script>
<script>
Vue.component('formulario',{
template: '#formulario',
data(){
return{
title:'',
}
}
,
methods:{
submit(){
this.$eventHub.$emit('submit', this.title);
console.log('Clicou');
}
}
});
Vue.component('list',{
template: '#list',
created(){
var vm = this;
this.$eventHub.$on('submit', function(title){
if(title){
vm.list.push({title:title});
}
});
},
data(){
return{
list:[
{title: "Ir a feira"},
{title: "Comprar Ovos"},
]
}
}
});
Vue.prototype.$eventHub = new Vue();
var vue = new Vue({
el:"#app",
data:{
title:"VueJS"
}
})
</script>