最近做项目需要分享功能,主要是几个国外的平台,需要分享到的平台:Facebook, LinkedIn,Twitter,Email
我是在nuxt3上使用的
安装:
//Yarn
yarn add vue-social-sharing@next
//Npm
npm install --save vue-social-sharing@next
使用:
//In your nuxt.config.js file:
modules: [ 'vue-social-sharing/nuxt' ]
上面这个方法有问题,会报:Cannot restart nuxt: Cannot read properties of undefined (reading 'Index') 错误 查看issue,有人给出了方案,自定义了 plugins/vue-social-sharing.ts
import { defineNuxtPlugin } from '#app'
import VueSocialSharing from "vue-social-sharing";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueSocialSharing);
});
vue页面引入:
<div>
<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>
</div>
<div>
<ShareNetwork
network="LinkedIn"
url="https://news.vuejs.org/issues/180"
>
Share on LinkedIn
</ShareNetwork>
</div>
<div>
<ShareNetwork
network="Twitter"
url="https://news.vuejs.org/issues/180"
title="Say hi to Vite! A brand new, extremely fast development setup for Vue."
hashtags="vuejs,vite"
twitter-user="thinkers_go"
>
Share on Twitter
</ShareNetwork>
</div>
<div>
<ShareNetwork
network="Email"
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."
>
Share on Email
</ShareNetwork>
</div>
即可使用,完美!!!!
[官方链接](https://github.com/nicolasbeauvais/vue-social-sharing)
