In the use of axios and springmvc When doing a small project with front and rear ends separated , encounter ,springmvc The data returned in response is json Format , But in vue When the scaffold is analyzed, it becomes string
this.$http.post("login", this.loginForm,{ emulateJSON:true,responseType:'json'}).then((response) => { // If not converted here, it will become a string , Other methods are not known for the time being var res=JSON.parse(response.data); alert(typeof response.data);// This is shown as string type if (res.flag) { this.$message.success(" Login successful "); this.$router.push({ path: "/home" }); // Storage user object window.sessionStorage.setItem("user",res.user) } else { this.$message.error(" Login failed "); } }); Back end java Code :```java @Autowired private UserService userService; @RequestMapping(value = "/login",produces = "application/json;charset=UTF-8") @ResponseBody public String login(@RequestBody User loginUser){ System.out.println(loginUser); User user = userService.login(loginUser); HashMap<String, Object> res = new HashMap<String, Object>(); boolean flag=false; if (user != null) { flag=true; } res.put("flag",flag); res.put("user",user); String resJson= JSON.toJSONString(res); System.out.println(resJson); return resJson; }