vue传数组到后台
使用框架有resful,spring,vue前台:<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script><script src="https://unpkg.com/axios/dist/axios.min.js"></script><script ...
·
使用框架有resful,spring,vue
前台:
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
var vue = new Vue({
el: "#order",
data: {
arrId: [0,1,2]
},
methods: {
loadCar: function() {
axios.get("http://localhost:8080/shoppingCar/arr/" + this.arrId)
.then(value => {
//this指的是当前vue对象,给vue中
this.shoppingCars = value.data.data;
})
}
},
mounted() {
this.loadCar();
}
});
</script>
后台:
package com.cdz.demo0216yiguo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("shoppingCar")
@CrossOrigin
public class ShoppingCarController {
@GetMapping("arr/{arrId}")
public JsonResult listShoppingCarArr(@PathVariable("arrId") List<Integer> arr){
try{
List list=new ArrayList();
for(int i:arr ){
//System.out.println(i+"------"+);
}
return new JsonResult(200,"success",list);
}catch (Exception e){
e.printStackTrace();
return new JsonResult(500,"failed",e.getMessage());
}
}
}
注:@CrossOrigin解决跨域(前后端离)
更多推荐
已为社区贡献1条内容
所有评论(0)