文章詳情頁面需要分享到第三方,包括qq、qq空間、微博、微信。

蜜獾互联网發表於2024-12-10

一、封裝一個share.js檔案,放在目錄/utils下

// share.js
 
// url - 需要分享的頁面地址(當前頁面地址)
// title - 分享的標題(文章標題)
 
export function toQQzone (url, title) {
  url = encodeURIComponent(url)
  title = encodeURIComponent(title)
  window.open(`https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${url}&title=${title}&desc=${title}&summary=${title}&site=${url}`)
}
 
export function toQQ (url, title) {
  url = encodeURIComponent(url)
  title = encodeURIComponent(title)
  window.open(`https://connect.qq.com/widget/shareqq/index.html?url=${url}&title=${title}&source=${url}&desc=${title}&pics=`)
}
 
export function toWeibo (url, title) {
  url = encodeURIComponent(url)
  title = encodeURIComponent(title)
  window.open(`https://service.weibo.com/share/share.php?url=${url}&title=${title}&pic=&appkey=&sudaref=`)
}
 
export function toWechat (url, title) {
  url = encodeURIComponent(url)
  title = encodeURIComponent(title)
  // console.log(21, process.env.NUXT_ENV_APISERVER)
  window.open(`${process.env.NUXT_ENV_APISERVER}/sharetoWechat?url=${url}&title=${title}`)
}

相關文章