
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<div id="app" v-cloak>
<h1>{{text}}</h1>
<input type="button" value="Get请求:获取文字" @click="getText">
<input type="text" v-model="inputVal">
<input type="button" value="Post请求:注册" @click="register">
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
text: "",
img: "",
inputVal: ""
},
methods: {
getText() {
var that = this;
axios.get("https://autumnfish.cn/api/joke").then(function (response) {
that.text = response.data;
}).catch(function (error) {
console.error(error);
})
},
register() {
var that = this;
axios.post("https://autumnfish.cn/api/user/reg", { username: that.inputVal }).then(function (response) {
that.text = response.data;
}).catch(function (error) {
console.error(error);
})
}
}
});
</script>
</body>
</html>