怎么设置小程序页面使用相机 微信小程序怎么设置相机

主机教程 建站分享 1年前 (2022-12-11) 213次浏览

文章摘要:怎么设置小程序页面使用相机 微信小程序怎么设置相机

设置小程序页面使用相机的案例: 在对应的wxml文件中添加以下代码: <camera devi […]

设置小程序页面使用相机的案例:

在对应的wxml文件中添加以下代码:

<camera device-position="back"  flash="off"binderror="error"style="width:100%;height:300px;"></camera>

<button type="primary"bindtap="takePhoto">拍照</button>

<view>预览</view>

<image mode="widthFix" src="{{src}}"></image>

在对应的js文件中添加以下代码:

// pages/headline/headline.js

Page({

takePhoto(){

   const ctx=wx.createCameraContext()

   ctx.takePhoto({

     quality:'high',

     success:(res)=>{

       this.set.Data({

         src:res.tempImagePath

       })

     }

   })

},

error(e){

   console.log(e.detail)

}

})


声明:
若非注明,本站文章源于互联网收集整理和网友分享发布,如有侵权,请联系站长处理。
文章名称:怎么设置小程序页面使用相机 微信小程序怎么设置相机
文章链接:https://www.7966.org/post/16990.html
转载请注明出处

喜欢 (0)