-
Notifications
You must be signed in to change notification settings - Fork 1
/
8. data and models.html
60 lines (48 loc) · 1.55 KB
/
8. data and models.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
<!DOCTYPE html>
<html>
<head>
<title>Data and models</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 d-flex flex-row">
<product inline-template>
<div class="card p-4 mr-4">
<div class="alert alert-warning">
Model: {{ name }}<br>
Year: {{ year }}<br>
Price: ${{ price }}
</div>
<h1 class="mb-2"><strong>Editing: </strong> {{ name }}</h1>
<form>
<input v-model="name">
<input v-model="year">
<input v-model="price">
<button class="btn btn-primary" @click.prevent="rename">Rename car</button>
</form>
</div>
</product>
</div>
<script type="text/javascript">
Vue.component('product', {
data() {
return {
name: 'Car X',
year: 2000,
price: 99.99
}
},
methods: {
rename() {
let newName = Math.floor((Math.random() * 100) + 1);
this.name = `Car ${newName}`;
}
}
})
new Vue({
el: '#my-app'
})
</script>
</body>
</html>