axios + vue

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<body>
	<div id="cors">
		<input type="button" @click="getUsers" id="cors" value="core跨域测试get"	/>
		<input type="button" @click="getUsersPost" id="cors" value="core跨域测试post"	/>
	</div>
</body>
<script>
	var app = new Vue({
     
     
	 	el:"#cors",
		data:{
     
     
			
		},
		methods:{
     
     
			getUsers:function(){
     
     
				axios.get("http://localhost:8080/user").then(function(response){
     
     
					console.log(response)
				},function(err){
     
     
					console.log(err)
				})
			},
			getUsersPost:function(){
     
     
				axios.post("http://localhost:8080/user").then(function(response){
     
     
					console.log(response)
				},function(err){
     
     
					console.log(err)
				})
			}
		}
	 })
</script>

</html>

おすすめ

転載: blog.csdn.net/qq_44132240/article/details/107350053