1、pages/index/index.js
const app = getApp()
var access_token
var accessToken
})
Page({
onLoad: function () {
var that = this;
var dname=123456
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token',
header: { 'content-type': 'application/json' },
data: {
grant_type: 'client_credential',
appid:'xxxxxxxxxxxxxx',
secret: 'xxxxxxxxxxxxxxxxx'
},
success(res) {
accessToken = res.data.access_token
wx.request({
url: 'https://api.weixin.qq.com/wxa/getwxacode?access_token='+accessToken,
method: 'POST',
responseType: 'arraybuffer',
data: {
"path": 'pages/index2/index?dname='+dname,
"width": 430,
},
success(res) {
let base64 = wx.arrayBufferToBase64(res.data)
let codeImg= 'data:image/PNG;base64,' + base64
console.log(codeImg)
that.setData({codeImg: codeImg})
},
})
}
})
},
})
2、pages/index/index.wxml
<view class="m">
<image style="width: 200px; height: 200px; background-color: #eeeeee;" src="{{codeImg}}"></image>
</view>
3、pages/index2/index.js
const DB= wx.cloud.database()
const db= wx.cloud.database()
Page({
onLoad: function (options) {
var dname=options.dname
this.setData({
dname:dname
})
DB.collection("sok").add({
data: {
dname:dname
}
})
},
4、pages/index2/index.wxml
<text>{{pdname2}}</text>
------------------------------------------------------------------------
在电脑上运行可以,在手机上运行不显示二维码?