uni-app+h5puls 编写相机拍照

<template>
  <view class="camera-page">
    <image :src="imgSrc" v-if="imgSrc"/>
    <button @click="openCamera">拍照</button>
  </view>
</template>

<script>
// import plus from '@/common/plus.js'

export default {
  data () {
    return {
      imgSrc: ''
    }
  },
  methods: {
    openCamera () {
      plus.camera.getCamera().captureImage((path) => {
          console.log(path)
        this.imgSrc = path
      }, (err) => {
        console.error('拍照失败:', err)
      })
    }
  }
}
</script>

<style>
  .camera-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .camera-page image {
    width: 200px;
    height: 200px;
    margin-bottom: 20px;
  }
</style>

 

posted @ 2023-02-10 16:40  「南邮」₩  阅读(262)  评论(0)    收藏  举报