handleSearch() { console.log(this.searchName) NameSearch(this.param).then(res => { if (this.studentName == res.studentName) { this.$message('查询成功'); } else { this.$message('查无此人'); } }); }补充代码以及相关逻辑,实现查询的功能
时间: 2024-04-12 12:28:45 浏览: 12
要实现查询功能,你需要提供以下代码和逻辑:
1. 请求方法和工具:你需要根据实际情况来定义请求方法和选择适合的工具来构建接口。例如,可以使用 axios 库来发送 HTTP 请求。
2. 补充代码:
```javascript
handleSearch() {
console.log(this.searchName);
// 发起请求
axios.get('/api/nameSearch', { params: this.param })
.then(res => {
// 处理返回结果
if (this.studentName === res.data.studentName) {
this.$message('查询成功');
} else {
this.$message('查无此人');
}
})
.catch(error => {
console.error('请求失败:', error);
this.$message('请求失败');
});
}
```
这段代码假设使用 axios 库发送 GET 请求到 `/api/nameSearch` 接口,并将 `this.param` 作为查询参数传递。在返回结果的处理中,如果返回的 `studentName` 与 `this.studentName` 相等,则显示查询成功的提示消息;否则显示查无此人的提示消息。如果请求失败,则会在控制台打印错误信息,并显示请求失败的提示消息。
请注意,这段代码仅提供了一个示例,并假设了使用 axios 库发送请求。你需要根据实际情况进行适当的修改和调整。