requestSpeedLimit.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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: "2G龟速", type: "2g", msg: "随机延迟30~60秒后响应" },
  25. { title: "3G慢速", type: "3g-", msg: "随机延迟10~30秒后响应" },
  26. { title: "3G略快", type: "3g", msg: "随机延迟3~10秒后响应" },
  27. { title: "4G弱网", type: "4g", msg: "随机延迟0.5~3秒后响应" },
  28. ],
  29. /**
  30. * 当前选中的索引
  31. */
  32. index: 0,
  33. };
  34. },
  35. mounted() {
  36. let cache = uni.getStorageSync("devtools_uniResLimitType");
  37. let index = this.typeList.findIndex((x) => x.type == cache);
  38. if (index == -1) index = 0;
  39. this.index = index;
  40. },
  41. methods: {
  42. /**
  43. * 选项发生改变事件
  44. */
  45. change(index) {
  46. uni.setStorageSync("devtools_uniResLimitType", this.typeList[index].type);
  47. this.index = index;
  48. },
  49. },
  50. };
  51. </script>
  52. <style lang="scss"></style>