https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js
localhost:8080/helloAxios?username=tom&password=123456&nick=汤姆
除了vue之外需要引入
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<h1>异步请求测试h1>
<div>
<input type="text" v-model="info">
<input type="button" value="异步Get请求" @click="f1()">
div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js">script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js">script>
<script>
let v=new Vue({
el:"body>div",
data:{
info:""
},
methods:{
f1(){
//发出异步的get请求 response代表响应,里面装着服务器的数据
axios.get("/helloAxios?info="+v.info).then(function (response) {
//服务器成功响应后会执行此处代码
alert(response.data);
})
}
}
})
script>
body>
html>
@RestController
public class AxiosController {
@RequestMapping("/helloAxios")
public String helleAxios(String info){
return "测试成功"+info;
}
}