react 添加addEventListener事件

export default function Index(props: any) {
    useEffect(() => {
      const getIssueDetail = (e) => {
        if (e.target.className.includes("xxxxxxxxxx")) {
          const type = e.target.dataset?.sourcetype;
          const id = e.target.dataset?.sourceid;
          switch (type) {
            case 'ISSUE':
            case 'DrawingSheet_ISSUE':
              xxxxxService.loadIssue(parseInt(id) || 0).then((res) => {
                if (res) {
                  return window.location.href = e.target.href;
                } else {
                  return message.error("aaaaaaaaaa");
                }
              }).catch((err) => {
                return message.error(err?.response?.msg ?? "系统错误");
              })
              break;
            default:
              return window.location.href = e.target.href;
          }
        }
      }
      document.addEventListener('click', getIssueDetail);
      return () => {
          document.removeEventListener('click', getIssueDetail);
      }
    }, [])
}

 

posted @ 2022-01-20 15:27  最好的年纪  阅读(697)  评论(0编辑  收藏  举报