Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
vue-catalogue
Advanced tools
这是一个文章目录组件,用于生成文章的目录,并附带平滑滚动和目录定位功能。
npm install --save vue-catalogue
<template>
<div>
<div id="article" v-html="content" />
<Catalogue selector="#article" />
</div>
</template>
<script>
import Catalogue from 'vue-catalogue'
export default {
components: { Catalogue }
}
</script>
样式采用stylus,使用前请确保安装相应的依赖。默认配置一共三项,组件部分细节如下:
export default {
···
props: {
selector: {
type: String,
required: true // 必须项,文章元素对应的选择器
},
title: {
type: String,
default: '目录'
},
asyncData: {
type: Boolean,
default: true
}
},
···
}
关于asyncData
配置项的说明:一般来说,文章的内容都是通过ajax
请求异步获取并渲染到页面上的,这意味着页面初始化时,目录组件是无法获取到dom元素的。以下是内部实现细节,通过父组件的updated
钩子来触发目录组件的初始化。
···
mounted () {
if (this.asyncData) {
this.$parent.$once('hook:updated', this.init)
} else {
this.init()
}
}
···
当然,如果你的文章内容是同步数据(即dom节点在组件初始化时已经存在在页面中),那么您可以通过设置:asyncData: false
<Catalogue selector="#article" :asyncData="false" />
当然,组件十分简单,总共不过200行代码,除去模板和样式,也许只有100行。如果您愿意,完全可以将组件从node_modules
中拿出来自行修改。
FAQs
make a catalog for articles
The npm package vue-catalogue receives a total of 1 weekly downloads. As such, vue-catalogue popularity was classified as not popular.
We found that vue-catalogue demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.