首页 > 解决方案 > [Vue 警告]:未知的自定义元素:- 您是否正确注册了组件?vue-社交分享

问题描述

尝试使用 vue-social-sharing(最新版本 2.4.3)库,但不断得到以下信息:

[Vue 警告]:未知的自定义元素:- 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。

我按照指南查看了代码示例。但是,似乎无法弄清楚我错过了什么或出错了。

我创建了一个单独的组件,并按照 vue-social-share 提供的示例进行操作。但仍然不断收到错误。

这是我的 main.js:

import Vue from 'vue'
import './plugins/vuetify'
import App from './App.vue'
import router from './router'
import store from './store'



Vue.config.productionTip = false;

let SocialSharing = require('vue-social-sharing');
Vue.use(SocialSharing);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');

这是我的组件(SocialSharingTest.vue):

<template>
<social-sharing url="https://vuejs.org/"
                      title="The Progressive JavaScript Framework"
                      description="Intuitive, Fast and Composable MVVM for building interactive interfaces."
                      quote="Vue is a progressive framework for building user interfaces."
                      hashtags="vuejs,javascript,framework"
                      twitter-user="vuejs"
                      inline-template>
  <div>
      <network network="email">
          <i class="fa fa-envelope"></i> Email
      </network>
      <network network="facebook">
        <v-icon class="mr-3" style="color: #3b5998">fab fa-facebook</v-icon>
      </network>
      <network network="googleplus">
        <i class="fa fa-google-plus"></i> Google +
      </network>

  </div>
</social-sharing>
</template>
<script>


  export default {
    name: "SocialSharingTest",
  }
</script>

<style scoped>

</style>

组件未按预期工作,并如上所述不断收到 **[Vue 警告]。我在这里看到了一个我希望看到的工作示例:

https://codesandbox.io/s/3yv7q36lq?from-embed

标签: vuejs2

解决方案


import SocialSharing from 'vue-social-sharing';

import Vue from 'vue'
const VueSelect = {
  install(Vue, options) {
    Vue.component('SocialSharing', SocialSharing)
  }
};
Vue.use(VueSelect)

你可以试试这个,看看它是否有效?


推荐阅读