【问题标题】:Gridsome: How to add Vue.use(MyPlugin) for a single page only?Gridsome:如何仅为单个页面添加 Vue.use(MyPlugin)?
【发布时间】:2021-03-31 08:53:20
【问题描述】:

我在所有页面上显示的 Gridsome main.js 中添加了使用 Vue.use(ReCaptcha, {some options}) 的 ReCaptcha 插件。

如何只在gridsome中为特定页面添加插件?

【问题讨论】:

    标签: vue.js gridsome gridsome-plugin


    【解决方案1】:

    我以前从未使用过 ReCaptcha 或 Gridsome,但通常,如果您使用 npm 安装插件,那么在单个页面上使用它的最简单方法是将插件导入到渲染的特定组件中你想使用它的路线。即

    /* === MyComponent.vue  === */
    <script>
    import plugin from 'packageName'; 
    // or 
    import { pluginExport } from 'packageName';
    
    export Default{
      // You can then use the plugin/pluginExport here 
    }
    

    从那里您应该能够像往常一样使用该特定组件中的包,如果您使用Vue.use 在应用程序范围内实现它。在某些情况下,根据插件的使用方式,您可能需要将导入的插件模块注册为components 对象中的子组件。比如this vuejs QR Code generator

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多