uniapp 调用拍照组件

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

代码示例:

<template>
	<view>
        <camera device-position="back" flash="off" @error="error" style="width: 100%; height: 300px;"></camera>
        <button type="primary" @click="takePhoto">拍照</button>
        <view>预览</view>
        <image mode="widthFix" :src="src"></image>
    </view>
</template>

export default {
    
    
    data() {
    
    
        return {
    
    
            src:""
        }
    },
    methods: {
    
    
         takePhoto() {
    
    
            const ctx = uni.createCameraContext();
            ctx.takePhoto({
    
    
                quality: 'high',
                success: (res) => {
    
    
                    this.src = res.tempImagePath
                }
            });
        },
        error(e) {
    
    
            console.log(e.detail);
        }
    }
}


猜你喜欢

转载自blog.csdn.net/maoge_666/article/details/131081194