一、需求
为了让用户能以更方便的形式邀请、添加好友或快速分享陪玩游戏系统源码中发现的趣事,在陪玩游戏系统源码开发时,就要实现二维码生成功能。
二、分析:技术栈
- 熟练em、rem、flex移动端布局
- 掌握原生Javascipt
- 掌握前端主流框架Vue
- 掌握axios请求方式
- 组件库Vant
- node npm包
三、流程:
1、点击陪玩游戏系统源码中分享按钮
2、获取到地址栏id
3、展示到陪玩游戏系统源码页面
四、项目具体分析
1、点击事件
Vue点击事件@click
2、 用组件库Vant简单布局
<!-- 二维码 -->
<van-overlay :show="show" @click="show = false">
<div class="wrapper">
<div class="block">
<p>分享</p>
<div>
<img :src="imrUrl" />
</div>
</div>
</div>
</van-overlay>
3、data里面的值
show: false,
imrUrl: ""
4、从npm.js官网下载插件,生成陪玩游戏系统源码所需二维码的插件
npm install --save qrcode
5、使用(官网)
import QRCode from 'qrcode' //那使用哪用
// With promises
QRCode.toDataURL('I am a pony!')
.then(url => {
console.log(url)
})
.catch(err => {
console.error(err)
})
6、点击事件的方法具体代码
// 点击分享
share() {
this.show = true;
let url = location.href;//获取当前地址栏的地址
console.log(url);
QRCode.toDataURL(url)
.then(tpian => {
console.log(tpian);
this.imrUrl = tpian;
})
.catch(err => {
console.error(err);
});
},
总结:
用户体验至上,阻挡不住我们开发的步伐。
以上就是“前端怎样写陪玩游戏系统源码中分享二维码的功能?”的全部内容,希望对大家在开发陪玩游戏系统源码时有帮助。