|
|
|
@ -1,12 +1,13 @@ |
|
|
|
import { ref, shallowRef, watch, toRaw, nextTick, onBeforeUnmount, type ShallowRef } from 'vue' |
|
|
|
import { ref, shallowRef, watch, toRaw, nextTick, onBeforeUnmount } from 'vue' |
|
|
|
import type { ShallowRef } from 'vue' |
|
|
|
|
|
|
|
type PageList = { name: string; shopList: Shop[] } |
|
|
|
/** |
|
|
|
* @param {array} totalList 分页数据源 |
|
|
|
* @param {*} scroll 滚动组件的实例 |
|
|
|
* @return {*} { scrollEnd, pageList, loaded } |
|
|
|
*/ |
|
|
|
type PageList = { name: string; shopList: Shop[] } |
|
|
|
export const usePage = (totalList: PageList[], scroll: ShallowRef<any>) => { |
|
|
|
export const usePage = (totalList: ShallowRef<PageList[]>, scroll: any) => { |
|
|
|
if (typeof Worker === 'undefined') { |
|
|
|
alert('抱歉,当前运行环境不支持Web Worker API, 请升级浏览器版本') |
|
|
|
} |
|
|
|
@ -27,16 +28,10 @@ export const usePage = (totalList: PageList[], scroll: ShallowRef<any>) => { |
|
|
|
function scrollEnd() { |
|
|
|
worker.value?.postMessage('scrollEnd') |
|
|
|
} |
|
|
|
watch( |
|
|
|
totalList, |
|
|
|
newVal => { |
|
|
|
const rawList = newVal.map(item => toRaw(item)) |
|
|
|
worker.value?.postMessage(rawList) |
|
|
|
}, |
|
|
|
{ |
|
|
|
immediate: true |
|
|
|
} |
|
|
|
) |
|
|
|
watch(totalList, newVal => { |
|
|
|
const rawList = newVal.map(item => toRaw(item)) |
|
|
|
worker.value?.postMessage(rawList) |
|
|
|
}) |
|
|
|
|
|
|
|
onBeforeUnmount(() => { |
|
|
|
worker.value?.terminate() |
|
|
|
|