vue+axios使用post请求

 1                     const _this = this;
 2                     const params = new URLSearchParams();
 3                     params.append('title', _this.repositoryTitle);
 4                     params.append('content', _this.InputContent);
 5                     axios.post("http://localhost:8080/repository/addRepository", params)
 6                         .then((response) => {
 7                             if (response.status === 200) {
 8                                 if (response.data === 'success') {
 9                                     _this.$message({
10                                         message: '提交成功,感谢您的贡献!',
11                                         type: 'success'
12                                     });
13                                     //调用延时之前先清除timer的延时
14                                     clearTimeout(this.timer); //清除延迟执行
15                                     this.timer = setTimeout(() => {  //设置延迟执行,为了能看到上面成功的提示
16                                         console.log('设置延迟执行为了能看到登录成功的提示');
17                                         window.location = "http://localhost:8080";//返回主页面
18                                     }, 1000);//延时1秒
19                                 } else {
20                                     _this.$message.error(response.data.toString());
21                                 }
22                             }
23                         }).catch((error) => {
24                         console.log.info('------->接口返回数据error', error);
25                         _this.$message.error(error.toString());
26                     });

 

posted @ 2022-04-26 01:24  勤快的懒羊羊  阅读(1055)  评论(0编辑  收藏  举报