-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
100 lines (98 loc) · 2.49 KB
/
index.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
<html>
<head>
<title>Vue Demo</title>
<style type="text/css">
.content {
width:80%;
margin:0 auto;
margin-bottom:20px;
}
.content .item{
width:20%;
float:left;
}
</style>
</head>
<body>
<form id="demo">
<div class="content" v-repeat="formData">
<div class="item">
<input type="text" v-model="msg">
</div>
<div class="item">
<input type="checkbox" v-model="checked">
</div>
<div class="item">
<select v-model="selected">
<option>one</option>
<option>two</option>
</select>
</div>
<div class="item">
<select v-model="multiSelect" multiple>
<option>one</option>
<option>two</option>
<option>three</option>
</select>
</div>
<div class="item">
<button type="button" v-on="click:remove(this)">X</button>
</div>
<div style="clear:both"></div>
</div>
<center><button v-on="click:onClick">Add One</button></center>
<center><button type="button" v-on="click:submit()">Submit</button></center>
<div><pre>data: {{$data | json 2}}</pre></div>
</form>
<script src="js/vue.min.js"></script>
<script type="text/javascript">
var selectURL = 'http://xxxxxxxx/data.php';
var request = new XMLHttpRequest();
var data;
request.open("GET","data.php?action=select&t=" + Math.random() + "",true);
request.send();
request.onload = function(){
data = JSON.parse(request.responseText);
vue();
};
function vue(){
var demo = new Vue({
el: '#demo',
data: {
name: "demo",
formData: data
},
methods: {
onClick:function(e){
e.preventDefault();
console.log(this);
this.formData.push({
id:"",
msg: "",
checked: "",
selected : "",
multiSelect: ""
})
},
remove:function(e){
if(e.$data.id!=""){
var remove = new XMLHttpRequest();
remove.open("GET","data.php?action=delete&id="+e.$data.id+"",true);
remove.send();
}
this.formData.$remove(e.$data)
},
submit:function(){
var result = JSON.stringify(demo.$data.formData);
result = "data="+result+"";
var submit = new XMLHttpRequest();
submit.open("POST","data.php?action=insert",true);
submit.setRequestHeader("Content-type","application/x-www-form-urlencoded");
submit.send(result);
}
}
});
}
</script>
</body>
</html>