vue+axios

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

获取天气的地址:http://wthrcdn.etouch.cn/weather_mini?city=福州

获取音乐的地址:https://autumnfish.cn/search?keywords=歌曲名称

具体歌曲:https://autumnfish.cn/song/url?id=

axios的语法:功能强大的网络请求库

axios.get(地址?key=value).then(fuction(response){},function(err){})

axios.post(地址,{key:value,....}).then(fuction(response){},function(err){})

 例子:

<div id="app">
<input type="button" value="get" @click="getInfo">
<input type="button" value="post" @click="postInfo">
<span v-text="message"></span>
</div>
var vm = new Vue({
el:"#app",
data : {
message :"info"
},
methods:{
getInfo:function () {
var thatInfo = this
axios.get("https://autumnfish.cn/api/joke").then(
function (response) {
thatInfo.message = response.data

},
function (err) {
console.log(err)
}
)
},
postInfo:function () {
console.log("post")

}
}
})


posted on 2021-12-16 10:24  bruce.sharp  阅读(89)  评论(0)    收藏  举报