Skip to content

Commit

Permalink
fix(core): 修复日志面板不会实时滚动的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Jun 11, 2022
1 parent ad8a684 commit a0b9fff
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/core/src/components/Terminal.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { defineComponent, nextTick, onMounted, watch } from 'vue';

import { domSearch } from '../core/utils';
import { panel } from '../start';
import { useStore } from '../store';

export const Terminal = defineComponent({
setup () {
const local = useStore('localStorage');

onMounted(() => {
// 控制台元素
const { terminal } = domSearch({ terminal: '.terminal' });
// 监听改变,并且滚动到最下方
watch(
() => local.logs,
watch(local.logs,
// eslint-disable-next-line vue/valid-next-tick
() => nextTick(() => scroll())
);
// 滚动到最下方
nextTick(() => scroll());

function scroll () {
if (terminal?.scrollHeight) {
terminal?.scrollTo({
behavior: 'auto',
top: terminal.scrollHeight
});
if (panel) {
// 控制台元素
const { terminal } = domSearch({ terminal: '.terminal' }, panel);
if (terminal?.scrollHeight) {
terminal?.scrollTo({
behavior: 'auto',
top: terminal.scrollHeight
});
}
}
}
});
Expand Down

0 comments on commit a0b9fff

Please sign in to comment.