|
2 | 2 | <div |
3 | 3 | class="progress-bar" |
4 | 4 | ref="progressBar" |
| 5 | + v-resize:[debounceOptions].debounce="handleResize" |
5 | 6 | @click.prevent.stop="progressClick" |
6 | 7 | > |
7 | 8 | <div |
@@ -36,6 +37,7 @@ import { debounce } from "@/utils/dom"; |
36 | 37 | export default { |
37 | 38 | name: "progressBar", |
38 | 39 | data() { |
| 40 | + this.debounceOptions = { wait: 50 }; |
39 | 41 | this.mouse = {}; // 记录鼠标位置,是否按下等信息 |
40 | 42 | return { |
41 | 43 | bufferedOffsetWidth: 0, |
@@ -64,29 +66,25 @@ export default { |
64 | 66 | default: false, |
65 | 67 | }, |
66 | 68 | }, |
67 | | - destroy() { |
68 | | - window.removeEventListener("resize", debounce(this.handleResize, 50)); |
69 | | - }, |
70 | 69 | mounted() { |
71 | 70 | this.changeProgressbarWidth(this.percent); |
72 | | - let _this = this; |
73 | | - window.addEventListener("resize", debounce(this.handleResize, 50)); |
| 71 | +
|
74 | 72 | const virtualBar = this.$refs.virtualBar; |
75 | 73 | virtualBar.addEventListener( |
76 | 74 | "mousemove", |
77 | | - debounce(function (e) { |
| 75 | + debounce((e) => { |
78 | 76 | e.stopPropagation(); |
79 | | - const progressBar = _this.$refs.progressBar; |
| 77 | + const progressBar = this.$refs.progressBar; |
80 | 78 | let pageX = e.pageX; |
81 | 79 | let diff = pageX - progressBar.getBoundingClientRect().left; |
82 | 80 | let percent = (diff / progressBar.clientWidth).toFixed(2); |
83 | | - _this.$emit("virtualBarMove", { pageX, percent }); |
| 81 | + this.$emit("virtualBarMove", { pageX, percent }); |
84 | 82 | }, 200) |
85 | 83 | ); |
86 | 84 | virtualBar.addEventListener( |
87 | 85 | "mouseleave", |
88 | | - debounce(function (e) { |
89 | | - _this.$emit("virtualBarLeave"); |
| 86 | + debounce(() => { |
| 87 | + this.$emit("virtualBarLeave"); |
90 | 88 | }, 200) |
91 | 89 | ); |
92 | 90 | }, |
|
0 commit comments