requestTimeoutMock.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <view>
  3. <MenuBtn
  4. :list="typeList"
  5. :value="index"
  6. @indexChange="change"
  7. title="超时:"
  8. />
  9. </view>
  10. </template>
  11. <script>
  12. import MenuBtn from "./menuBtn.vue";
  13. export default {
  14. components: {
  15. MenuBtn,
  16. },
  17. data() {
  18. return {
  19. /**
  20. * 随机响应超时
  21. */
  22. typeList: [
  23. { title: "无", type: "", msg: "正常响应请求" },
  24. { title: "5%", type: "5", msg: "随机5%的概率请求响应超时或报错" },
  25. { title: "10%", type: "10", msg: "随机10%的概率请求响应超时或报错" },
  26. { title: "30%", type: "30", msg: "随机30%的概率请求响应超时或报错" },
  27. { title: "50%", type: "50", msg: "随机50%的概率请求响应超时或报错" },
  28. { title: "70%", type: "70", msg: "随机70%的概率请求响应超时或报错" },
  29. { title: "90%", type: "90", msg: "随机90%的概率请求响应超时或报错" },
  30. { title: "100%", type: "100", msg: "所有请求均响应超时或报错" },
  31. ],
  32. /**
  33. * 当前选中的索引
  34. */
  35. index: 0,
  36. };
  37. },
  38. mounted() {
  39. let cache = uni.getStorageSync("devtools_uniResTimeout");
  40. let index = this.typeList.findIndex((x) => x.type == cache);
  41. if (index == -1) index = 0;
  42. this.index = index;
  43. },
  44. methods: {
  45. /**
  46. * 选项发生改变事件
  47. */
  48. change(index) {
  49. uni.setStorageSync("devtools_uniResTimeout", this.typeList[index].type);
  50. this.index = index;
  51. },
  52. },
  53. };
  54. </script>
  55. <style lang="scss"></style>