4

如何配置 Prism 以使用 Nuxt?我在文件中将其添加为供应商nuxt.config.js

// * Build configuration

build: {
  // * You can extend webpack config here
  vendor: ['axios', 'prismjs'],

  extend(config, ctx) {
    if (ctx.isServer) {
      config.externals = [
        nodeExternals({
          whitelist: [/^vuetify/]
        })
      ];
    }
  }
}

然后在脚本部分的页面中导入它:

<script>
import Prism from'prismjs';

export default {
  data() {
    return {
      post: {}
    };
  },
// more data...

那我该怎么用呢?我试过在mounted中调用它,但它不起作用。不会返回任何错误,但不会更改站点上的任何内容。

mounted() {
  Prism.highlightAll();
}
4

1 回答 1

1

原来是工作,只是忘了包括css样式。

于 2018-09-13T07:09:18.810 回答