nuxt3网站文章分享微信 ,QQ功能

1.安装

npm install qrcode --save-dev

2.组件使用

javascript 复制代码
  
          <div class="share">
            <div style="line-height: 69px; color: #fff;width: 100px;">
              <p style="text-align: center;">分享:</p>
            </div>

            <div @click="shareToMicroblog()" class="BJ_WB">
              <a class="weibo" />
              <a>微博</a>
            </div>

            <!-- <div @click="shareToQQ()" class="BJ_QQ">
                <a class="qq"></a>
                <a>QQ好友</a>
              </div> -->

            <div
              class="BJ_WX"
              @mouseover="showQR = true"
              @mouseleave="showQR = false"
            >
              <div class="weixinall">
                <a class="weixin" />
                <a>微信</a>
              </div>
              <div
                class="weixincode"
                :class="{ 'qrcode-visible': showQR }"
                style="
                  position: absolute;
                  top: -220px;

                  opacity: 0;
                  transition: opacity 0.3s ease;
                  width: 200px;
                  height: 200px;
                  background-color: #fff;
                "
              >
                <canvas
                  id="QRCode_header"
                  style="width: 165px; height: 165px; margin: auto"
                />
                <p
                  style="
                    color: #818181;
                    font-size: 12px;
                    line-height: 16px;
                    margin-left: 15px;
                  "
                >
                  打开微信扫一扫<br />将您喜欢的内容分享微信朋友圈
                </p>
              </div>
            </div>

            <div class="BJ" @click="shareToQQRom()">
              <a class="qqkj"></a>
              <a>QQ</a>
            </div>
          </div>
javascript 复制代码
<script setup lang="ts">
import QRCode from "qrcode";
const route = useRoute();
const id = ref(route.params.id);
const showQR = ref(false);
const shareUrl = `https://XXXXXXX.COM/XXXXXXXXXX/${id.value}`;
//分享到QQ
// const shareToQQ= function() {
//   window.open(
//       `https://connect.qq.com/widget/shareqq/index.html?url=${shareUrl}&title=${sysInfo}&source=${shareUrl}&desc=${sysInfo}&pics=`)
// }
//分享到微信
onMounted(() => {
  const QR_OPTIONS = {
    errorCorrectionLevel: "H",
    width: 165,
    height: 165,
    margin: 3,
    color: {
      dark: "#000",
      light: "#fff",
    },
    
  };

  QRCode.toCanvas(
    document.querySelector("#QRCode_header"),
    shareUrl,
    QR_OPTIONS,
    (error: any) => {
      if (error) console.error("二维码生成失败:", error);
    }
  );
});

//分享到微博
const shareToMicroblog = function () {
  window.open(
    `https://service.weibo.com/share/share.php?url=${shareUrl}&title=${details.value.productBackground}`
  );
};

//分享到qq空间
const shareToQQRom = function () {
  const pics = encodeURIComponent(details.value.productBackgroundImage);
  const desc = encodeURIComponent(details.value.productBackground);
  window.open(
    `https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${shareUrl}&title=${details.value.productBackground}&summary=${details.value.productBackground}&desc=${desc}&pics=${pics}`
  );
};
</script>
css 复制代码
<style scoped lang="scss">
.share {
  display: flex;
  flex-wrap: nowrap;
  width: 100%;
  justify-content: center;
  .weibo {
    display: block;
    width: 24px;
    height: 21px;
    background-image: url("/assets/img/wb.png") !important;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: 50% 50%;
  }

  .BJ_WB {
    background-color: #e6162d;
    width: 110px;
    height: 40px;
    margin-top: 15px;
    margin-right: 15px;
    display: flex;
    border-radius: 8px;
    justify-content: center;
    align-items: center;
    color: #fff;
    cursor: pointer;
    &:hover {
      background-color: #f75567;

      transform: translateY(-2px);
    }
  }

  .BJ_QQ {
    background-color: #2384cc;
    width: 110px;
    height: 40px;
    margin-top: 15px;
    margin-right: 15px;
    display: flex;
    border-radius: 8px;
    justify-content: center;
    align-items: center;
    color: #fff;
    cursor: pointer;
    &:hover {
      background-color: #5faae2;
      transform: translateY(-2px);
    }
  }

  .BJ_WX {
    background-color: #3cb034;
    width: 110px;
    height: 40px;
    margin-top: 15px;
    border-radius: 8px;
    /* position: relative; */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s;
    color: #fff;
    cursor: pointer;
    &:hover {
      background-color: #7dd377;
      transform: translateY(-2px);
    }
  }

  .BJ {
    background-color: rgb(255, 206, 0);
    width: 110px;
    height: 40px;
    display: flex;
    border-radius: 8px;
    justify-content: center;
    align-items: center;
    color: #fff;
    margin: 15px;
    cursor: pointer;
    &:hover {
      background-color: #ffde52;
      transform: translateY(-2px);
    }
  }

  .qq {
    display: block;
    width: 28px;
    height: 28px;
    background-image: url("/assets/img/qq.png");
    background-size: cover;
    background-repeat: no-repeat;
    background-position: 50% 50%;
  }
  .qqkj {
    display: block;
    width: 28px;
    height: 28px;
    background-image: url("/assets/img/qqkj.png");

    background-size: cover;
    background-repeat: no-repeat;
    background-position: 50% 50%;
  }

  .weixinall {
    position: relative;
    display: flex;
    justify-content: center;
    .weixin {
      display: block;
      width: 28px;
      height: 28px;
      background-image: url("/assets/img/wx.png");
      background-size: cover;
      background-repeat: no-repeat;
      background-position: 50% 50%;
    }
    .weixincode {
      position: absolute;
      left: -60px;
      z-index: 1000 !important;
    }
  }
}

.qrcode-visible {
  opacity: 1 !important;
  pointer-events: auto;
}
</style>

效果



相关推荐
阿砾1 天前
微信群消息处理:回调乱序、自己发的消息、群内真实发送者
微信
承渊政道1 天前
飞牛NAS部署Hermes AI Agent:接入DeepSeek、微信与公网访问完整教程
人工智能·微信·nas·deepseek·hermes
高晶2 天前
微信小程序实战:iOS 降级查询工具从零开发
微信·程序员
软擎3 天前
花店节日布置怎么留记录?用轻虾导出助手把花材替换、现场尺寸与撤场清点钉在一起
微信
jaysee-sjc3 天前
【苍穹外卖】Day12:工作台数据看板与 Excel 报表导出
java·开发语言·数据库·spring boot·spring·微信·excel
极客互动API4 天前
【极客互动】企业微信外部群聊机器人开发实战与效果验证
微信·机器人·企业微信·企微scrm·企业微信api·企微外部联系人
特视界说5 天前
多规格产品动画怎么规划?把“一个型号一条片”改成可管理的内容架构
人工智能·安全·微信·新浪微博
悟空码字6 天前
视频号直播变了
微信·视频号
随性而行3607 天前
企业微信 Webhook 接收不到消息?网络连通性、URL 签名验签与 API 返回错误码排查指南
java·网络·人工智能·后端·微信·企业微信
未秃头的程序猿8 天前
同一个商户号,V2 免密代扣和 V3 分账的证书怎么共存?
java·后端·微信