【问题标题】:How to use 'Vue plugin components' inside my custom vue plugin如何在我的自定义 vue 插件中使用“Vue 插件组件”
【发布时间】:2019-09-04 11:22:52
【问题描述】:

我正在尝试在我创建的自定义 vue 插件中使用 vuetify 组件,但似乎我的插件在应用程序“知道”存在 vuetify 之前呈现。

我曾尝试在我的插件中使用 Vue.use(Vuetify),但它不起作用,基本上,在我的插件中使用它没有意义,因为我希望插件用户(开发人员)将 vuetify 用作他的应用程序中的全局依赖项,因此它可以渗透到我的插件中

这是我的vue html插件模板:

<v-content>
      <v-container fluid fill-height>
        <v-layout justify-center>
        <div v-if="videoLoading">
          <v-progress-circular v-if="useVuetifyLoader"
            :size="size"
            :width="width"
            :rotate="rotate" 
            :value="videoLoadingProgress*1.5"
            :color="color"
          >
            Downloading...
            {{ `${loadedInMB}/${totalInMb}Mb` }}
          </v-progress-circular>
          <div v-else>
              Downloading...
              {{ `${loadedInMB}/${totalInMb}Mb` }}
          </div>
        </div>
        <div v-else>
          <div>
            <div>foo</div>
          </div>
        </div>
      </v-layout>
    </v-container>
  </v-content>

这是我的插件:

import MyPlugin from '../lib/MyPlugin.vue';
import Vuetify from 'vuetify'


const install = function (Vue, config) {

Vue.component("my-plugin", MyPlugin)

}




export { install }

*and i tried also :*



 import MyPlugin from '../lib/MyPlugin.vue';
    import Vuetify from 'vuetify'


    const install = function (Vue, config) {
    Vue.use(Vuetify)// <-- did not work
    Vue.component("my-plugin", MyPlugin)

    }




    export { install }

当我在其他应用中实现我的插件时,我遇到了这些错误:

Unknown custom element: <v-content> - did you register the component correctly? For recursive components, make sure to provide the "name" option

 Unknown custom element: <v-container> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

Unknown custom element: <v-layout> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

Unknown custom element: <v-progress-circular> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

【问题讨论】:

    标签: javascript npm plugins vuejs2


    【解决方案1】:

    如何设置您的插件并在其中包含自定义组件:

    export default {
      install (Vue, options) {
         Vue.anyMethodYouLike = (value) => value
    
         Vue.component('v-content', Component);
         // Add `Vue.mixin()` to inject options to all components.
         Vue.mixin({
             // Add component lifecycle hooks and/or properties.
             created() {
             }
         });
         // We can also add Vue instance methods by attaching them to Vue.prototype.
         Vue.property.$myProperty = 'This is a Vue instance property.'
      }
    }
    

    然后在您的应用中使用,例如:

    import myPlugin from './plugin.js' // the file with the code above
    
    Vue.use(myPlugin, {
      someProp: 'blahdy blah'  //options to pass
    })
    

    【讨论】:

      【解决方案2】:

      好的,所以我想通了。 我所要做的就是将 Vuetify 作为参数传递给 options 对象,然后我可以在我的插件文件中使用 Vue.use(my_vuetify_param)

      【讨论】:

        猜你喜欢
        • 2019-12-25
        • 1970-01-01
        • 2019-12-04
        • 1970-01-01
        • 2021-02-06
        • 1970-01-01
        • 2020-08-26
        • 2023-03-21
        • 2020-06-29
        相关资源
        最近更新 更多