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 @   勤快的懒羊羊  阅读(1069)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示