大家早上好,我正在做一个分为两部分的项目:
我有一些问题,找到了正确的结构和技术,在前端使用。我应该用纯javascript工作吗?我应该使用VueJS/Angular/其他js框架吗?
后端是用编写的。
在未来,前端也将有一个功能预订约会,选择一个时隙日期。
对于前端,我尝试使用XMLHttpRequest,但我有一些问题要获取和发布数据与API (代码运行,但什么都没有发生)。
我试着用这个平庸的代码
var xmlhttp = new XMLHttpRequest();
var url = "API_URL";
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
myFunction(myArr);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();发布于 2019-04-28 12:38:26
这取决于您的用例。我可以分类如下。请参考链接(https://medium.freecodecamp.org/do-we-still-need-javascript-frameworks-42576735949b)
发布于 2019-04-28 12:01:45
您可以尝试使用javascript axios库。Javascript侧示例:
import axios from 'axios'
axios.get('/springEndpoint').then((response) => {
console.log(response.data);
// do something with response
}).catch(() => {
// do something in case of an error
})弹簧控制器示例:
@RestController
public class TestController {
@GetMapping("/springEndpoint")
public String someEndpoint() {
return "test response";
}
}如果您正在寻找一种使用vue.js构建spring引导web应用程序的方法,这可能对您有用:https://blog.codecentric.de/en/2018/04/spring-boot-vuejs/。
https://stackoverflow.com/questions/55889875
复制相似问题