-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
160 lines (150 loc) · 3.51 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="https://cdn.bootcss.com/wangEditor/10.0.13/wangEditor.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="https://cdn.bootcss.com/wangEditor/10.0.13/wangEditor.min.js"></script>
<script>
axios.defaults.baseURL = 'http://127.0.0.1:3000'
axios.defaults.headers.withCredentials = true
</script>
<style>
#main {
max-width: 1024px;
margin: 0 auto;
}
input {
margin: 10px 0;
font-size: 14px;
line-height: 20px;
width: 100%;
}
</style>
</head>
<body>
<div id=main>
<h1>hello,{{username}}</h1>
<h2>发表文章</h2>
<form>
<input type="text" v-model=form.title>
<div ref="editor"></div>
<button @click.prevent=submit>提交</button>
<button @click.prevent=submitAmount>批量提交</button>
<button @click.prevent=removeAmount>批量删除</button>
</form>
<input type="text" v-model=page>
<button @click=refresh>获取</button>
<ul>
<li v-for="e in list" :key="e._id">
<h3>
<span @click.prevent=remove(e._id)>X</span>
<span>{{e.title}}</span>
<span>{{e.author && e.author.name}}</span>
</h3>
<article v-html=e.content></article>
</li>
</ul>
<h2>创建用户</h2>
<form>
<input type="text" v-model=userForm.username>
<input v-model=userForm.password type="password">
<button @click.prevent=submitUser>创建新用户</button>
</form>
<ul>
<li v-for="e in userList" :key="e._id">
<span @click.prevent=removeUser(e._id)>X</span> {{e.username}} </li>
</ul>
<h2>登录</h2>
<form>
<input type="text" v-model=loginForm.username>
<input type="password" v-model=loginForm.password>
<button @click.prevent=login>登录</button>
</form>
</div>
<script>
let app = new Vue({
el: '#main',
data: {
list: [],
userList: [],
username: '',
page: 0,
form: {
title: '',
content: ''
},
userForm: {
},
loginForm: {
}
},
methods: {
refresh() {
axios.get('article', {
params: {
page: this.page,
count: 10000
}
}).then(res => {
this.list = res.data
})
},
submit() {
let data = Object.assign(this.form)
data.author = this.userList[0]._id
axios.post('article', this.form).then(res => {
this.refresh()
})
},
remove(_id) {
axios.delete('article/' + _id).then(res => {
this.refresh()
})
},
refreshUser() {
axios.get('user').then(res => {
this.userList = res.data
})
},
submitUser() {
axios.post('user', this.userForm).then(res => {
this.refreshUser()
})
},
removeUser(_id) {
axios.delete('user/' + _id).then(res => {
console.log(res)
this.refreshUser()
}).catch((err) => {
console.log(err.response.data.msg)
})
},
login() {
axios.post('login', this.loginForm).then(res => {
console.log(res)
})
}
},
created() {
this.refresh()
this.refreshUser()
axios.get('profile').then(res => {
this.username = res.data.username
})
},
mounted() {
var editor = new wangEditor(this.$refs.editor)
editor.customConfig.uploadImgServer = '/upload'
editor.customConfig.onchange = html => {
this.form.content = html
}
editor.customConfig.uploadFileName = 'images'
editor.create()
}
})
</script>
</body>
</html>