首先,创建Camera目录和page
camera.xml的代码如下
<camera device-position="{
{show}}" flash="off" binderror="error" style="width: 100%; height: 400px;"></camera>
<view class='weui-cell__ft'>
<switch checked bindchange='switch1Change'></switch>
</view>
<view class="weui-btn-area">
<button class="weui-btn" type="primary" bindtap="takePhoto">拍照 </button>
</view>
camera.js代码
拍照和录像的方法如下
// 拍照
takePhoto() {
this.ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
wx.uploadFile({
url: '', //仅为示例,非真实的接口地址
filePath: this.d