Nuxtjs如何引入代码高亮prismjs

一,安装prismjs

npm install prismjs

二,配置nuxt.config.js

在nuxt.config.js文件中添加prism插件

export default {
  plugins: [
    '~/plugins/prism'
  ],
}

三,编写插件

目录app/plugins/prism.js

import Prism from 'prismjs'
import 'prismjs/themes/prism-tomorrow.css' // 选择你喜欢的主题
export default Prism

四,引用插件

在需要的页面,例如/pages/detail/_id.vue

export default {
  ...
  mounted(){
    Prism.highlightAll()
  },
  ...
}