fetchCardData(){ let _this=this; this.$axios.get("http://localhost:8080/softwork_war/Servletfindallbook").then(function(response){ _this.cardList = response.data; _this.card.id = response.data.id; _this.card.imageUrl = response.data.img; _this.card.title = response.data.bookname; }).catch(function(err){ console.log(err); }); },
时间: 2024-02-15 09:28:47 浏览: 23
这段代码是使用 axios 库向本地服务器发送 GET 请求,获取名为 "http://localhost:8080/softwork_war/Servletfindallbook" 的 API 接口返回的数据,并将数据赋值给卡片列表 this.cardList 中。同时也将卡片的 id、图片地址和标题从返回的数据中分别取出,并赋值给 this.card 对象的相应属性。在请求过程中,如果发生错误,则通过 catch 语句捕获并输出错误信息到控制台。
相关问题
this.$axios.get("http://bjb.yunwj.top/php/tk/cb.php")怎么添加请求参数
要添加请求参数到这个 GET 请求中,你可以在 URL 后面使用查询字符串的形式来传递参数。查询字符串是将参数以键值对的形式附加到 URL 的末尾,使用 `?` 连接 URL 和查询字符串,多个参数之间使用 `&` 符号分隔。
例如,如果你需要添加一个名为 `param1` 的参数和一个名为 `param2` 的参数,你可以将请求代码修改为:
```javascript
this.$axios.get("http://bjb.yunwj.top/php/tk/cb.php?param1=value1¶m2=value2")
```
其中 `value1` 和 `value2` 是参数的具体值。
在实际开发中,你可能需要根据变量或用户输入来动态生成参数。在这种情况下,你可以使用模板字符串或拼接字符串的方式构建请求 URL,例如:
```javascript
const param1 = "value1";
const param2 = "value2";
const url = `http://bjb.yunwj.top/php/tk/cb.php?param1=${param1}¶m2=${param2}`;
this.$axios.get(url);
```
这样就可以将动态生成的参数添加到请求 URL 中。请根据你的具体需求和参数进行相应的修改。
goBack() { this.$router.push("/manageEvent") }, getEvent(){ let _this = this axios.get('http://localhost:8082/event/getEvent?name=' +_this.$route.query.name) .then(function (ref) { _this.eventInformation = ref.data.data[0] console.log(_this.eventInformation.venueId) _this.imageUrl = `http://localhost:8082/common/download?name=${_this.eventInformation.picture}` axios.get('http://localhost:8082/venue/getVenue?id=' +_this.eventInformation.venueId) .then(function (ref) { console.log(ref.data) _this.venue = ref.data.data.name _this.university = ref.data.data.university }) }) },
这段代码是关于前端页面中获取活动信息和场馆信息的部分代码。其中,getEvent()函数使用了axios库向后端发送请求,获取活动信息和对应的场馆信息,并将它们赋值给前端页面中的变量。具体来说,它通过调用axios.get()方法发送GET请求,其中请求的URL包括了活动名称和场馆ID。然后,使用.then()方法对请求的结果进行处理,在回调函数中将返回的活动信息和场馆信息赋值给前端页面中的变量,并打印出场馆ID和场馆名称。最后,获取到的活动图片URL会赋值给imageUrl变量。另外,goBack()函数则是实现了路由的跳转,将页面跳转到“/manageEvent”路由下。