<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue整合axios</title>
</head>
<body>
<div id="app">
<input type="button" value="获取数据" @click="getData">
<p v-text="message"></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios@0.21.1/dist/axios.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
message: ''
},
methods: {
getData: function () {
let that = this;
axios.get('https://autumnfish.cn/search?keywords=%E6%B5%B7%E9%98%94%E5%A4%A9%E7%A9%BA')
.then(function (response) {
that.message = response.data.result.songCount;
}, function (err) {
console.log(err);
})
}
}
})
</script>
</body>
</html>