pc端支付宝支付和微信支付(vue)

微信扫码支付
需要用到的插件 : qrcodejs2
先安装 cnpm i qrcodejs2 -S
然后引入:import QRCode from "qrcodejs2";
配置啥的照着官网写就ok了
在这里插入图片描述
点击后弹窗出现,就有惊喜
在这里插入图片描述
代码如下:

<template>
  <div class="box">
    <el-button type="success" @click="payOrder">点我有惊喜</el-button>
    <el-dialog width="300px" title="微信支付" @close="closeCode" :visible.sync="show" append-to-body>
      <div class="paycode">
        <!-- 放置二维码的容器,需要给一个ref -->
        <div id="qrcode" ref="qrcode"></div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import QRCode from "qrcodejs2";
export default {
  data() {
    return {
      show: false
    };
  },
  methods: {
    // 展示二维码
    payOrder() {
      this.show = true;
      // 二维码内容,由后台返回的地址
      this.qrcode = "https://www.baidu.com/?tn=21002492_25_hao_pg";
      // 使用$nextTick确保数据渲染
      this.$nextTick(() => {
        this.crateQrcode();
      });
    },
    // 生成二维码
    crateQrcode() {
      this.qr = new QRCode("qrcode", {
        width: 130,
        height: 130, // 高度
        text: this.qrcode, // 二维码内容
        background: "#f0f"
      });
    },
    // 关闭弹框,清除已经生成的二维码
    closeCode() {
      this.innerVisible = false;
      this.$refs.qrcode.innerHTML = "";
    }
  }
};
</script>

<style>
#qrcode {
  display: flex;
  justify-content: center;
}
</style>

支付宝支付
调接口后端返回的是form 表单
在这里插入图片描述
单击支付宝支付后出现支付界面:
在这里插入图片描述

自己也在学习中,加油!!!

  • 5
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值