@RestController
@RequestMapping("test")
@Slf4j
public class testController {
@GetMapping("t1")
public String t1(){
log.info("正在访问测试控制器......");
return "this is test one";
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="js/vue.js"></script>
<script src="js/axios-0.18.0.js"></script>
<!-- 从js下的vue.js引入 -->
</head>
<body>
<div id="app">
<!-- 这里是 Vue 实例的模板 -->
<p>{{ message }}</p>
</div>
</body>
<script>
const app = new Vue({
el: '#app', // 指定 Vue 实例的挂载点
data: {
message: 'Hello, Vue!' // 定义 Vue 实例的数据
},
created() {
// 在 Vue 实例创建时调用 query 函数
this.query();
},
methods: {
query() {
// 在这里编写 query 函数的逻辑
console.log('query function is called');
axios.get("http://localhost:8081/test/t1")
.then(({data}) => {
if (data) {
console.log(data);
} else {
console.log("响应体为空");
}
})
.catch(err => {
console.log("Axios发生异常!!!");
// location.href = "http://localhost:8080/testErr.html";
});
}
}
});
</script>
</html>
这是一个本地项目、并没有部署到nginx上、在浏览器中浏览时为什么控制台会输出发生异常?
服务端正常接收到请求并响应
