-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5. props.html
116 lines (88 loc) · 3.21 KB
/
5. props.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
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html>
<head>
<title>Props</title>
<script type="text/javascript" src="https://vuejs.org/js/vue.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
</head>
<body>
<div id="my-app" class="container pt-4">
<h1>Props</h1>
<props api-endpoint="/contact-us">
</props>
<h1 class="mt-5">Parsed props vs Unparsed props</h1>
<div>
<parsing inline-template
user-name="Owen"
unparsed-json="{'username': 'owen'}"
:user-id="1"
:parsed-json="{'username': 'owen'}"
>
<ul class="mt-4">
<li><strong>Unparsed String:</strong> {{ userName }} - {{ typeof userName }}</li>
<li><strong>Parsed String:</strong> {{ userId }} - {{ typeof userId }}</li>
<li><strong>Unparsed String:</strong> {{ unparsedJson }} - {{ typeof unparsedJson }}</li>
<li><strong>Parsed String:</strong> {{ parsedJson }} - {{ typeof parsedJson }}</li>
</ul>
</parsing>
</div>
<h1 class="mt-5">Prop inheritance (children & Parents)</h1>
<family family="famo" :parsed-family="famo" inline-template>
<div class="mt-4">
<code>$this.family = {{ family }};</code><br>
<code>$this.parsedFamily = {{ parsedFamily }};</code>
<div class="mt-4">
<button class="btn btn-danger" @click="pushBaby">I'm inside the child!</button>
</div>
</div>
</family>
<div class="mt-4 alert-success p-2">
Im (g)root.<br><br>
<button class="btn btn-primary" @click="newFamo">Modify Parent</button>
</div>
<h1 class="mt-5">Prop validation</h1>
<mad-props :id="2" :settings="{'enabled': true}"></mad-props>
</div>
<script type="text/javascript">
Vue.component('props', {
props: ['apiEndpoint'],
template: `<div>{{ apiEndpoint }}</div>`
})
Vue.component('parsing', {
props: ['userName', 'userId', 'unparsedJson', 'parsedJson']
})
Vue.component('family', {
props: ['family', 'parsedFamily'],
methods: { pushBaby() { this.parsedFamily.push('Baby'); } }
})
Vue.component('mad-props', {
props: {
name: {
type: String,
default: 'No name'
},
id: {
type: Number,
required: true
},
settings: {
type: Object,
required: true,
}
},
template: `<div class="my-4 p-2 card">
Name: {{ name }}<br>
ID: {{ id }}<br>
Enabled: {{ settings.enabled }} (default is false)
</div>`
})
new Vue({
el: '#my-app',
data: {
famo: ['Dad', 'Mum', 'Aunt Jan', 'Terry']
},
methods: { newFamo() { this.famo.push('Dog'); } }
})
</script>
</body>
</html>