-
Notifications
You must be signed in to change notification settings - Fork 303
/
46.复习-父子组件之间的传值.html
55 lines (54 loc) · 1.35 KB
/
46.复习-父子组件之间的传值.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
<!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">
<script src="./lib/vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
<com1 :data1="data1" @func="getMsgFromSon">
</com1>
</div>
<template id="tmp1">
<div>
<h1>brooo--------{{data1}}</h1>
<input type="button" value="给父组件传值" @click="sendMsg">
</div>
</template>
<script>
var com1 = {
template: "#tmp1",
props: ['data1'],
data(){
return {
sonMsg:'hi dady'
}
},
methods: {
sendMsg(){
this.$emit('func', this.sonMsg)
console.log(this.sonMsg)
}
},
}
var vm = new Vue({
el: '#app',
data: {
data1: 'data from father',
msgFromSon: ''
},
methods: {
getMsgFromSon(data){
this.msgFromSon = data
}
},
components:{
com1
}
})
</script>
</body>
</html>