-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
怎么记录滚动位置 #1
Comments
import {
defineComponent,
HTMLAttributes,
onActivated,
reactive,
ref
} from "vue";
import Style from "./ScrollBody.module.scss";
export default defineComponent({
name: "ScrollBody",
setup: (props: HTMLAttributes, { slots }) => {
const mainDiv = ref<HTMLElement | null>(null);
const offset = reactive({ left: 0, top: 0 });
const onScrollHandle = (event: UIEvent) => {
if (event.target instanceof HTMLElement) {
offset.top = event.target.scrollTop;
offset.left = event.target.scrollLeft;
}
props.onScroll?.(event);
};
onActivated(() => {
if (mainDiv.value === null || (offset.top === 0 && offset.left === 0))
return;
mainDiv.value.scroll({ left: offset.left, top: offset.top });
});
return () => {
return (
<main onScroll={onScrollHandle} ref={mainDiv} class={Style.scrollView}>
{slots.default?.()}
</main>
);
};
}
});
我一般会把应用中用到的滑动部分,单独做成一个组件,由它自己管理自己的滑动位置 |
直接上生产项目,抛出了两个警告 injection "Symbol([vue-router]: router)" not found. Unhandled error during execution of setup function 然后抛出了一个错误 ypeError: Cannot read property '___0x30_navigation_listened' of undefined 切图仔,没时间看源码,能指点一下吗 |
给一个复现的例子?这样我也不好找,或者看下例子 |
稍等,我复制一份最小的例子给你 |
老哥有啥进展没 |
最近一直在忙 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我有一个嵌套的视图组件
我想让不同的页面滚动条位置都可以正确的展示,有什么好的方法吗
The text was updated successfully, but these errors were encountered: