searchbuilding:function(){ var that=this; axios.post("/building/search",{ buildname: this.searchbuildingname, college:this.searchcollege, username:this.searchusername }) .then(function (response) { alert("搜索成功"); $("#table").bootstrapTable('load', response.data.list); alert("搜索"); }),function (err) { alert("搜索失败"); console.log(err); } }这个方法的$("#table").bootstrapTable('load', response.data.list);报错:TypeError: Cannot read properties of undefined (reading 'total') at e.value
时间: 2024-02-14 07:21:06 浏览: 139
这个错误提示是在调用bootstrap-table的load函数时出现的。具体来说是load函数要使用一个undefined的属性'total',导致了TypeError。建议检查代码,看看是否正确地使用了bootstrap-table相关的函数和参数,是否有缺失或者错误。另外,也可以检查一下response.data.list的数据格式是否正确,是否缺失了'total'属性。
相关问题
axios.defaults.baseURL = 'http://localhost:8080/book/'; var vm = new Vue({ el: '#app', data: { id: '', bookName:'', flag: false, submitFlag: false, books: [] }, methods:{ handle: async function () { //编辑 var book = { id: this.id, bookName: this.bookName }; await axios.put(book.id, book); await this.queryBooks(); this.id = ''; this.bookName = ''; this.flag = false; }, //编辑处理 toEdit: async function (id) { var response = await axios.get(id); this.id = response.data.id; this.bookName = response.data.bookName; this.flag = true; }, deleteBook: async function (id) { }, queryBooks: async function () { var response = await axios.get(); this.books = response.data; } }, computed:{ total: function () { return this.books.length; } }, watch: { name: function (val) { console.log(val); } }, mounted:function () { this.queryBooks(); } });请补全代码通过axois远程交互操作图书信息。
以下是补全代码:
```
axios.defaults.baseURL = 'http://localhost:8080/book/';
var vm = new Vue({
el: '#app',
data: {
id: '',
bookName:'',
flag: false,
submitFlag: false,
books: []
},
methods:{
handle: async function () {
//编辑
var book = {
id: this.id,
bookName: this.bookName
};
await axios.put(book.id, book);
await this.queryBooks();
this.id = '';
this.bookName = '';
this.flag = false;
},
//编辑处理
toEdit: async function (id) {
var response = await axios.get(id);
this.id = response.data.id;
this.bookName = response.data.bookName;
this.flag = true;
},
deleteBook: async function (id) {
await axios.delete(id);
await this.queryBooks();
},
queryBooks: async function () {
var response = await axios.get();
this.books = response.data;
}
},
computed:{
total: function () {
return this.books.length;
}
},
watch: {
name: function (val) {
console.log(val);
}
},
mounted:function () {
this.queryBooks();
}
});
```
以上代码通过使用axios库实现了查询、编辑、删除图书的功能。其中,axios库用于向服务器发送请求,获取图书信息,同时也可以用于更新和删除图书。此外,该代码中使用了Vue.js框架来实现数据的双向绑定,以及实现响应式的页面更新。
<script src="../static/axios/dist/axios.min.js"></script>如何创建一个实例
在使用`axios`库创建HTTP请求时,首先需要在HTML页面中引入axios的JS文件。你已经给出了引入axios.min.js的方式,接下来我会告诉你如何创建一个axios实例:
```html
<script>
// 引入axios库
<script src="../static/axios/dist/axios.min.js"></script>
<!-- 然后在JavaScript部分 -->
window.onload = function () {
// 创建axios实例
const axiosInstance = axios.create({
baseURL: '你的API基础URL', // 如果你的API不是默认的基础URL,这里需要配置
timeout: 5000, // 设置超时时间
headers: {'Content-Type': 'application/json'}, // 设置默认头信息
});
// 使用axiosInstance发起请求
axiosInstance.get('/api/data') // 替换为你要访问的API路径
.then(response => {
console.log(response.data); // 打印响应数据
})
.catch(error => {
console.error(error); // 打印错误信息
});
};
</script>
```
上面的代码中,`axios.create()`函数用于创建一个新的axios实例,其中配置了一些默认选项。你可以根据实际需求自定义这些配置项。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)