微信小程序接口封装wx.hideLoading()后wx.showToast()不弹出的问题

原文链接:https://blog.csdn.net/Anna0115/article/details/105370982


     
     
  1. getDate(){
  2. wx.showLoading({
  3. title: '加载中',
  4. });
  5. wx.request({
  6. url: 'test.php', //仅为示例,并非真实的接口地址
  7. data: {},
  8. header: {
  9. 'content-type': 'application/json' // 默认值
  10. },
  11. success (res) {
  12. wx.showToast({
  13. title: '请求成功',
  14. icon: 'success'
  15. })
  16. },
  17. fail(res){
  18. wx.showToast({
  19. title:res.data.message,
  20. icon: 'none'
  21. })
  22. })
  23. },
  24. compelet(){
  25. wx.hideLoading();
  26. }
  27. })
  28. }

上面操作的话,wx.hideLoading()之后wx.showToast()就无法触发。wx.showToast()本身就有wx.hideLoading()的属性,wx.showToast()显示的时候,即使没调用wx.hideLoading()方法,上面的wx.showLoading({title:'加载中'})也会消失。


  
  
  1. getDate(){
  2. wx.showLoading({
  3. title: '加载中',
  4. });
  5. wx.request({
  6. url: 'test.php', //仅为示例,并非真实的接口地址
  7. data: {},
  8. header: {
  9. 'content-type': 'application/json' // 默认值
  10. },
  11. success (res) {
  12. if(如果有toast提示){
  13. wx.showToast({
  14. title: '提示内容',
  15. icon: 'success'
  16. })
  17. } else{
  18. wx.hideLoading()
  19. }
  20. },
  21. fail(res){
  22. wx.showToast({
  23. title: res.data.message,
  24. icon: 'none'
  25. })
  26. })
  27. },
  28. compelet(){
  29. }
  30. })
  31. }

  
  
  1. getDate(){
  2. wx.showLoading({
  3. title: '加载中',
  4. });
  5. wx.request({
  6. url: 'test.php', //仅为示例,并非真实的接口地址
  7. data: {},
  8. header: {
  9. 'content-type': 'application/json' // 默认值
  10. },
  11. success (res) {
  12. wx.showToast({
  13. title: '请求成功',
  14. icon: 'success'
  15. })
  16. },
  17. fail(res){
  18. wx.showToast({
  19. title:res.data.message,
  20. icon: 'none'
  21. })
  22. })
  23. },
  24. compelet(){
  25. wx.hideLoading();
  26. }
  27. })
  28. }

猜你喜欢

转载自blog.csdn.net/xiaoma19941027/article/details/106538881