Vue.js------网络请求库axios(四)
一、引入axios资源库<script src="https://unpkg.com/axios/dist/axios.min.js"></script>二、事例代码<!DOCTYPE html><html><head><meta charset="utf-8" /><title>axi...
·
一、引入axios资源库
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
二、事例代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>axios 网络请求库</title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入axios资源库 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<input type="button" value="获取笑话" @click="getjoke" />
<p> {{joke}}</p>
</div>
<script type="text/javascript">
var app = new Vue({
el: "#app",
data: {
joke: "这是一条笑话",
},
methods: {
getjoke: function() {
var that = this;
axios.get("https://autumnfish.cn/api/joke").then(function(response) {
console.log(response.data);
that.joke = response.data;
}, function(err) {})
}
},
})
</script>
</body>
</html>
三、总结
更多推荐
已为社区贡献4条内容
所有评论(0)