element-plus 老版本cascader使用卡死问题

Published: · LastMod: October 18, 2023 · 167 words

element-plus 老版本cascader使用卡死 🔗

重写Cascader组件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { defineComponent, onMounted, onBeforeMount } from "vue"
import { ElCascader } from "element-plus";

function cascaderVisable() {
  const children = document.querySelectorAll(
    ".el-cascader-panel .el-cascader-menu"
  );
  Array.from(children).map((item) => item.removeAttribute("id"));
}

export default defineComponent({
  extends: ElCascader,
  name: "ElCascader",
  setup(props, ctx) {
    const observer = new MutationObserver(cascaderVisable)
    onMounted(() => {
      observer.observe(document.body,{ attributes: true, childList: true, subtree: true })
    })
    onBeforeMount(() => {
      observer.disconnect()
    })
    return ElCascader.setup(props, ctx)
  },
});

references 🔗

https://github.com/ElemeFE/element/issues/22060