Renderless components give you the highest possible control over your markup and styling. This means that vue-social-sharing
ship with minimal HTML and no CSS to let you adapt the look and feel of the components to your needs. You can learn more about renderless components in this blog article by @adamwathan.
Before using this package it is important to understand how Social Networks handle sharing links on their platform. When you share a link on a Social Network, the Social Network will crawl the link to detect Open Graph meta tags. If you share links that do not contain Open Graph meta tags, the Social Network will not be able to display a rich content for your link. You can refer to the Available properties section of the documentation to check which Social Network accept which properties without Open Graph tags.
# Yarn
yarn add vue-social-sharing
# NPM
npm install --save vue-social-sharing
import VueSocialSharing from 'vue-social-sharing'
Vue.use(VueSocialSharing);
// In your nuxt.config.js file:
modules: [
'vue-social-sharing/nuxt'
]
<script src="/dist/vue-social-sharing.js"></script>
<ShareNetwork
network="facebook"
url="https://news.vuejs.org/issues/180"
title="Say hi to Vite! A brand new, extremely fast development setup for Vue."
description="This week, I’d like to introduce you to 'Vite', which means 'Fast'. It’s a brand new development setup created by Evan You."
quote="The hot reload is so fast it\'s near instant. - Evan You"
hashtags="vuejs,vite"
>
Share on Facebook
</ShareNetwork>
The url
is the only property required for all networks.
Name | Data Type | Description |
---|---|---|
tag |
String | HTML tag used to render the network component. Default to "a" tag. |
Prop | Type | Description |
---|---|---|
url |
String | URL to share. |
title |
String | Sharing title (if available). |
description |
String | Sharing description (if available). |
quote |
String | Facebook quote (Facebook only). |
hashtags |
String | A list of comma-separated hashtags (Twitter and Facebook). |
twitter-user |
String | Twitter user (Twitter only). |
media |
String | Url to a media (Pinterest, VK, Weibo, and Wordpress). |
Network | url |
title |
description |
Extras/Comments |
---|---|---|---|---|
Baidu | ✔️ | ✔️ | ❌ | |
Buffer | ✔️ | ✔️ | ❌ | |
✔️ | ✔️ | ✔️ | ||
EverNote | ✔️ | ✔️ | ❌ | |
✔️ | ✔️ | ✔️ | hashtags A list of comma-separated hashtags, only the first one will used.quote Facebook quote. |
|
✔️ | ✔️ | ❌ | ||
HackerNews | ✔️ | ✔️ | ❌ | |
InstaPaper | ✔️ | ✔️ | ✔️ | |
Line | ✔️ | ✔️ | ✔️ | |
✔️ | ❌ | ❌ | ||
Odnoklassniki | ✔️ | ✔️ | ❌ | |
✔️ | ✔️ | ❌ | media URL of an image describing the content. |
|
✔️ | ✔️ | ❌ | ||
✔️ | ✔️ | ❌ | ||
Skype | ✔️ | ✔️ | ✔️ | |
SMS | ✔️ | ✔️ | ✔️ | |
StumbleUpon | ✔️ | ✔️ | ❌ | |
Telegram | ✔️ | ✔️ | ✔️ | |
Tumblr | ✔️ | ✔️ | ✔️ | |
✔️ | ✔️ | ❌ | hashtags A list of comma-separated hashtags.twitter-user Twitter user to mention. |
|
Viber | ✔️ | ✔️ | ✔️ | |
VK | ✔️ | ✔️ | ✔️ | media URL of an image describing the content. |
✔️ | ✔️ | ❌ | media URL of an image describing the content. |
|
✔️ | ✔️ | ✔️ | ||
Wordpress | ✔️ | ✔️ | ✔️ | media URL of an image describing the content. |
✔️ | ✔️ | ❌ | ||
Yammer | ✔️ | ✔️ | ✔️ |
For the networks: Line
, Skype
, SMS
, Telegram
, Viber
, WhatsApp
and Yammer
; the shared content is a string of the form: "$title
$url
$description
"
Events that are emitted on the vue $root instance:
Name | Data | Description |
---|---|---|
share_network_open |
Network name, shared url | Fired when a sharing popup is open |
share_network_change |
Network name, shared url | Fired when the user open a new sharing popup while another is already open |
share_network_close |
Network name, shared url | Fired when a sharing popup is closed or changed by another popup |
You can listen to a vue-social-sharing
$root event by using the following code:
Vue.$root.$on('share_network_open', function (network, url) {
// your event code
});
Events that are emitted on the local vue-social-sharing
instance:
Name | Data | Description |
---|---|---|
open |
Network name, shared url | Fired when a sharing popup is open |
change |
Network name, shared url | Fired when the user open a new sharing popup while another is already open |
close |
Network name, shared url | Fired when a sharing popup is closed or changed by another popup |
You can listen to a ShareNetwork
local event by using the following code:
<ShareNetwork @open="open" @change="change" @close="close" />
Note that the
share_network_close
event will not be fired for the WhatsApp, SMS and Email sharers.
In version 3.x
you can extend and override the list of available networks. You can see a working example of the feature in the examples/index.js
file:
import Vue from 'vue'
import VueSocialSharing from '@/vue-social-sharing'
Vue.use(VueSocialSharing, {
networks: {
fakeblock: 'https://fakeblock.com/share?url=@url&title=@title'
}
})
new Vue({
el: '#app',
})
You can extend the list of available networks directly in your nuxt.config.js
file:
modules: [
['vue-social-sharing/nuxt', {
networks: {
fakeblock: 'https://fakeblock.com/share?url=@url&title=@title'
}
}],
]
Feel free to open an issue to ask for a new social network support.
Detailed changes for each release can be found in CHANGELOG.md.
Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.
Please make sure to read the Contributing Guide before making a pull request.