Vue.js------网络请求库axios(四)

一、引入axios资源库

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

Vue.js------网络请求库axios(四)_第1张图片

二、事例代码

<!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>

三、总结

Vue.js------网络请求库axios(四)_第2张图片

你可能感兴趣的:(Vue.js,vue)