#### camera
> 基礎庫 1.6.0 開始支持,低版本需做[兼容處理](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html)
系統相機。
需要[用戶授權](https://mp.weixin.qq.com/debug/wxadoc/dev/api/authorize-index.html) scope.camera
| 屬性名 | 類型 | 默認值 | 說明 |
| --------------- | ----------- | ---- | --------------------- |
| device-position | String | back | 前置或后置,值為front, back |
| flash | String | auto | 閃光燈,值為auto, on, off |
| bindstop | EventHandle | | 攝像頭在非正常終止時觸發,如退出后臺等情況 |
| binderror | EventHandle | | 用戶不允許使用攝像頭時觸發 |
相關api:[wx.createCameraContext](https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-camera.html)
##### 注意事項
1. `tip`: `camera` 組件是由客戶端創建的原生組件,它的層級是最高的,不能通過 z-index 控制層級。可使用 `cover-view` `cover-image`覆蓋在上面。
2. `tip`: 同一頁面只能插入一個 `camera` 組件。
3. `tip`: 請勿在 `scroll-view`、`swiper`、`picker-view`、`movable-view` 中使用 `camera` 組件。
**示例:**
```
<!-- camera.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>
// camera.js
Page({
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
}
})
},
error(e) {
console.log(e.detail)
}
})
```
- 簡介
- 第一章 公眾號開發
- 使用微信JSSDK
- 接口權限配置
- 分享接口
- 隱藏按鈕項
- 微信支付
- 第二章 小程序開發
- 基礎知識
- 分包加載
- WXSS樣式表
- 配置
- app.json配置
- window
- tabBar
- page.json配置
- 邏輯層
- app.js
- 場景值
- page.js
- 初始化數據
- 生命周期函數
- 頁面相關事件處理函數
- 事件處理函數
- 頁面實例方法
- 路由
- 文件作用域
- 模塊化
- 視圖層
- 模板語法
- 列表渲染
- 條件渲染
- 模板
- 事件
- 引用
- WXS語法規范
- WXS數據類型
- WXS控制流程
- WXS基礎類庫
- 組件
- 視圖容器
- view
- scroll-view
- swiper
- movable-view
- cover-view
- 基礎組件
- icon
- text
- rich-text
- progress
- 表單組件
- button
- checkbox
- form
- input
- label
- picker
- picker-view
- radio
- slider
- switch
- textarea
- 導航組件
- navigator
- 媒體組件
- audio
- image
- video
- camera
- 地圖組件
- map
- 畫布組件
- canvas
- 開放能力
- web-view
- 自定義組件
- 組件模版和樣式
- Component
- 組件傳值
- 組件事件
- Behaviors
- 組件間關系
- 網絡請求
- wx.request
- 微信登錄
- 獲取 openid 和 unionid
- 獲取用戶信息
- 將 wx.request 封裝為 promise
- 上傳圖片接口封裝
- 數據存儲
- 存儲數據和讀取數據
- 獲取數據緩存信息
- 移除數據緩存
- 獲取用戶設置
- openSetting
- getSetting
- 第三章 小游戲開發
- 參考資料