2024年Web前端最新vue2_markdown的内容目录生成_vue2 md目录不展示(1),2024年最新字节前端面试题

结束

一次完整的面试流程就是这样啦,小编综合了腾讯的面试题做了一份前端面试题PDF文档,里面有面试题的详细解析,分享给小伙伴们,有没有需要的小伙伴们都去领取!

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

💖 渲染选项

vue-markdown提供的参数详情

PropTypeDefaultDescribe
watchesArray["source", "show", "toc"]HTML refresh automatically when the prop in this array changed
sourceStringnullthe markdown source code
showBooleantrueenable render to the default slot automatically
htmlBooleantrueenable HTML syntax in source
xhtml-outBooleantrue<br></br> => <br />
breaksBooleantrue\n => <br>
linkifyBooleantrueautoconvert URL-like text to link
emojiBooleantrue:) => 😃
typographerBooleantrueenable some language-neutral replacement and quotes beautification
lang-prefixStringlanguage-CSS language prefix for fenced blocks
quotesString“”‘’use “”‘’ for Chinese, „“‚‘ for German, «»„“ for Russian
table-classStringtablecustomize html class of the <table>
task-listsBooleantrueenable GFM task list
tocBooleanfalseenable automatic table of contents
toc-idStringundefinedthe HTML id to render TOC
toc-classStringtablecustomize html class of the <ul> wrapping the TOC
toc-first-levelNumber2use 2 if you want to skip <h1> from the TOC
toc-last-levelNumber'toc-first-level' + 1use 5 if you want to skip <h6> from the TOC
toc-anchor-linkBooleantrueenable the automatic anchor link in the headings
toc-anchor-classStringtoc-anchorcustomize the anchor class name
toc-anchor-link-symbolString#customize the anchor link symbol
toc-anchor-link-spaceBooleantrueenable inserting a space between the anchor link and heading
toc-anchor-link-classStringtoc-anchor-linkcustomize the anchor link symbol class name
anchorAttributesObject{}anchor tag attributes such as target: '_blank' or rel: 'nofollow'
prerenderFunction (String) Stringnullfilter function before markdown parse
postrenderFunction (String) Stringnullfilter function after markdown parse
组件配置:
<template>
  <div style="width: 100%">
    <MarkDirTree :dirContent="dirContent"/>
    <VueMarkdown
      :source="content"
      :toc="true"
      v-highlight
      style="width: 100%; text-align: left"
    ></VueMarkdown>
  </div>
</template>
<script>
import MarkDirTree from './MarkDirTree'
export default {
    components: {MarkDirTree},
    name: 'DesignMarkdown',
    props: {
        contentSource: undefined
    },
    data () {
        return {
            content: '',
            dirContent: []
        }
    },
    watch: {
        contentSource: {
            handler (newVal) {
                this.content = newVal || ''
                this.getDirContent(newVal)
            },
            deep: true,
            immediate: true
        }
    },
    mounted () {
        console.log('design vuemarkdown')
    },
    methods: {
        // 树状目录获取
        getDirContent (mdContent) {
            if (!mdContent) {
                return []
            }
            const lineT = mdContent.split('\n')
            const titleArray = lineT.filter(item => item && item[0] === '#')
            console.log('titleArray', titleArray)
            const dirArray = titleArray.map(item => {
                return item.replace(/\r/g, '')
            })
            console.log('dirArray', dirArray)
            const dirLevelArray = dirArray.map(item => {
                let level = 0
                for (let loc in item) {
                    if (item[loc] === '#') {
                        ++level
                    }
                }
                const itemBack = item
                const value = itemBack.replace(/#/g, '').trim()
                return {
                    level,
                    value
                }
            })
            console.log('dirLevelArray', dirLevelArray)
            this.dirContent = dirLevelArray
        }
    }
}
</script>


渲染样式效果如下:

markdown-render

注意:
toc是markdown渲染的id显示
渲染内容如下图:
title-toc-render

💖 取出markdown的标题层级

字符串处理识别#标记层级,拿出数据内容
应为markdown本身有序,所以无需排序
渲染目录逻辑

  1. 根据层级渲染缩进
  2. 渲染标题内容
  3. 标题加上锚点跳转事件

渲染目录代码如下:

<template>
  <div class="markdown-link">
    <div v-for="(item,index) in content" :key="index">
      <div>
        <template v-for="levelItem in item.level">
          &nbsp;
        </template>
        <span @click="jumpText(item)" class="link-title">{{item.value}}</span>
      </div>
    </div>
  </div>
</template>
<script>

export default {
    props: {
        dirContent: undefined
    },
    data () {
        return {
            content: ''
        }
    },
    watch: {
        dirContent: {
            handler (newVal) {
                console.log('newVal', newVal)
                this.content = newVal || ''
            },
            deep: true,
            immediate: true
        }
**ES6**

*   列举常用的ES6特性:

*   箭头函数需要注意哪些地方?

*   let、const、var

*   拓展:var方式定义的变量有什么样的bug?

*   Set数据结构

*   拓展:数组去重的方法

*   箭头函数this的指向。

*   手写ES6 class继承。

**[开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0)**

![](https://img-blog.csdnimg.cn/img_convert/aac1740e50faadb9a6a7a5b97f9ccba8.png)



**微信小程序**

*   简单描述一下微信小程序的相关文件类型?

*   你是怎么封装微信小程序的数据请求?

*   有哪些参数传值的方法?

*   你使用过哪些方法,来提高微信小程序的应用速度?

*   小程序和原生App哪个好?

*   简述微信小程序原理?

*   分析微信小程序的优劣势

*   怎么解决小程序的异步请求问题?



![](https://img-blog.csdnimg.cn/img_convert/60b1dbe5c76e264468aa993416a9a031.png)



**其他知识点面试**

*   webpack的原理

*   webpack的loader和plugin的区别?

*   怎么使用webpack对项目进行优化?

*   防抖、节流

*   浏览器的缓存机制

*   描述一下二叉树, 并说明二叉树的几种遍历方式?

*   项目类问题

*   笔试编程题:



![](https://img-blog.csdnimg.cn/img_convert/aec12fc95e5722b9f2f1f22eeb5e67bd.png)



#### 最后



技术栈比较搭,基本用过的东西都是一模一样的。快手终面喜欢问智力题,校招也是终面问智力题,大家要准备一下一些经典智力题。如果排列组合、概率论这些基础忘了,建议回去补一下。

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现 markdown 目录自动生成可以使用 markdown-it 插件,并结合 vue.js 实现。可以按以下步骤进行操作: 1. 安装依赖:`npm install markdown-it --save` 2. 在 vue 组件中引入 markdown-it:`import MarkdownIt from 'markdown-it'` 3. 创建 markdown-it 实例:`const md = new MarkdownIt()` 4. 解析 markdown 内容生成 html:`const html = md.render(markdownContent)` 5. 使用正则表达式从生成的 html 中提取出所有标题(如 h1、h2、h3 等),并生成目录列表。 6. 将目录列表渲染到页面上。 以下是一个简单的实现示例: ```vue <template> <div> <div class="markdown-body" v-html="html"></div> <div class="toc" v-html="toc"></div> </div> </template> <script> import MarkdownIt from 'markdown-it' export default { data() { return { html: '', toc: '', } }, mounted() { const md = new MarkdownIt() const markdownContent = '# Title1\nContent1\n## Title2\nContent2\n### Title3\nContent3' const html = md.render(markdownContent) const toc = this.generateToc(html) this.html = html this.toc = toc }, methods: { generateToc(html) { const toc = [] const headers = html.match(/<h\d.*?>(.*?)<\/h\d>/gi) if (headers) { headers.forEach((header) => { const level = header.match(/<h(\d).*?>/i)[1] const title = header.replace(/<\/?h\d>/gi, '') toc.push(`<li class="toc-level-${level}"><a href="#">${title}</a></li>`) }) } return toc.length ? `<ul>${toc.join('')}</ul>` : '' }, }, } </script> ``` 在上面的示例中,我们首先创建了一个 markdown-it 实例,然后使用 render 方法将 markdown 内容转换成 html。接着,我们通过正则表达式从 html 中提取出所有标题,并生成目录列表。最后,将目录列表渲染到页面上。 需要注意的是,上面的示例只实现了基本的目录生成功能。如果需要更复杂的功能,可以考虑使用已有的 markdown-it 插件或者编写自己的插件来实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值