1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| { data() { return { showCatalog: true, catalogArr: [], }; }, async mounted() { this.init(); }, methods: { async init() { await this.$nextTick(); this.catalogArr = this.getCatalog("v-show-content"); }, getCatalog(className) { let showDom = document.querySelector("." + className); const headings = showDom.querySelectorAll( "h1, h2, h3, h4, h5, h6" ); let num = 0; return Array.from(headings).map((heading) => { num += 1; let cName = "z_catalog_" + num; heading.classList.add(cName); const level = parseInt(heading.tagName.charAt(1)); const title = heading.textContent; return { level: level, title: title, className: cName, }; }); }, scrollToDiv(className) { let mDom = document.querySelector("." + className); mDom.scrollIntoView({ behavior: "smooth" }); }, }, };
|