Commit 8ddcc27b0d025126bc3ba3fad767a6a14a9891f3

Authored by Aaron
1 parent 68a82b73
Exists in master and in 1 other branch legacy

修复addEventListener报错

Showing 1 changed file with 9 additions and 7 deletions   Show diff stats
examples/views/layout/component.vue
... ... @@ -101,13 +101,15 @@ export default {
101 101 let anchorList = [];
102 102 for (let index in domList) {
103 103 let dom = domList[index] || {};
104   - dom.addEventListener('click', e => {
105   - // 阻止a标签的默认行为
106   - e = e || window.event;
107   - e.preventDefault();
108   - document.documentElement.scrollTop = dom.offsetTop - headerHeight;
109   - this.$router.replace({ path: this.$route.path, hash: dom.hash });
110   - });
  104 + if (dom.addEventListener) {
  105 + dom.addEventListener('click', e => {
  106 + // 阻止a标签的默认行为
  107 + e = e || window.event;
  108 + e.preventDefault();
  109 + document.documentElement.scrollTop = dom.offsetTop - headerHeight;
  110 + this.$router.replace({ path: this.$route.path, hash: dom.hash });
  111 + });
  112 + }
111 113 if (dom.parentNode) {
112 114 const text = `${dom.parentNode.innerHTML}`.replace(/<\/?.*[^>]*>/g, '').trim();
113 115 if (text === 'API') {
... ...