回答編集履歴
2
ちょうせい
test
CHANGED
@@ -63,3 +63,57 @@
|
|
63
63
|
</script>
|
64
64
|
|
65
65
|
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
# methodつかわない
|
70
|
+
|
71
|
+
```javascript
|
72
|
+
|
73
|
+
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
|
74
|
+
|
75
|
+
<div id="app">
|
76
|
+
|
77
|
+
<input type="text" @input="e=>product=products.filter(x=>x.id==e.target.value).pop()||{}">
|
78
|
+
|
79
|
+
<ul>
|
80
|
+
|
81
|
+
<li>果物名:{{ product.name }}</li>
|
82
|
+
|
83
|
+
<li>値段:{{product.price}}円</li>
|
84
|
+
|
85
|
+
<li>配送料:{{product.delv}}円</li>
|
86
|
+
|
87
|
+
</ul>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
<script>
|
92
|
+
|
93
|
+
var app = new Vue({
|
94
|
+
|
95
|
+
el: '#app',
|
96
|
+
|
97
|
+
data: {
|
98
|
+
|
99
|
+
products: [
|
100
|
+
|
101
|
+
{ id: 1, name: 'りんご', price: 1580, delv: 900 },
|
102
|
+
|
103
|
+
{ id: 2, name: 'オレンジ', price: 1580, delv: 800 },
|
104
|
+
|
105
|
+
{ id: 3, name: 'ぶどう', price: 1580, delv: 600 },
|
106
|
+
|
107
|
+
{ id: 4, name: 'なし', price: 980, delv: 500 },
|
108
|
+
|
109
|
+
],
|
110
|
+
|
111
|
+
product:{},
|
112
|
+
|
113
|
+
},
|
114
|
+
|
115
|
+
});
|
116
|
+
|
117
|
+
</script>
|
118
|
+
|
119
|
+
```
|
1
chousei
test
CHANGED
@@ -34,9 +34,7 @@
|
|
34
34
|
|
35
35
|
var v=e.target.value;
|
36
36
|
|
37
|
-
|
37
|
+
this.product=this.products.filter(x=>x.id==v).pop()||{};
|
38
|
-
|
39
|
-
this.product=(product.length>0)?product[0]:{};
|
40
38
|
|
41
39
|
},
|
42
40
|
|