Using a javascript library/plugin within Vue code

☆樱花仙子☆ 提交于 2021-01-28 14:18:48

问题


So, I am trying to use the pretty neat component vue-social-sharing but this is the first time I am using such a libaray and am not sure how to set it up properly.

I have installed it via NPM, but then get lost on the first section "Usage, Loading the library"

Specifically, it says

"Browserify / Webpack"
var SocialSharing = require('vue-social-sharing');
Vue.use(SocialSharing);

But, I am not exactly sure where that goes, how it is setup etc. Do I set it in some Webpack file somewhere? or create its own file and import? Or, if it is in a normal vue file, which level? per component, per view? on the App.vue level?

I just don't really understand how exactly to set this up.

Any help would be great, I am completely lost as this is my first time using external libraries like this.

Thanks!


回答1:


That code you should put it inside main.js file which will initialize using that plugin (library):

import Vue from 'vue';
var SocialSharing = require('vue-social-sharing');
Vue.use(SocialSharing);

new Vue({
    ....
  })

and the following code you could put it inside any child component template:

<social-sharing url="https://vuejs.org/" inline-template>
 <div>
    <network network="facebook">
      <i class="fa fa-fw fa-facebook"></i> Facebook
   </network>
    ....
 </social-sharing>


来源:https://stackoverflow.com/questions/54147456/using-a-javascript-library-plugin-within-vue-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!