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
|
// <-----html----->
#app
input(v-for="item in b" type="radio" name="a" @click="change(item)")
p {{a}}
// <-----js----->
let app = new Vue({
el: "#app",
data:{
a: "",
b:[
{name: "蘋果", amount: 100},
{name: "香蕉", amount: 300},
{name: "鳳梨", amount: 500}
],
},
methods:{
change: function(item){
switch(item.name){
case "蘋果":
this.a = 100;
break;
case "香蕉":
this.a = 300;
break;
case "鳳梨":
this.a = 500;
break;
}
}
}
});
|