vue开发app项目,涉及原生接口调用,用hbuilder打包

使用vue开发app项目,怎么使用手机的原生功能,以获取手机的相册,调用摄像头为例。
这里使用的是hbuilder打包。
第一步:
定义一个vue组件,代码如下:

<template>
  <div class="mui-content">
    <button @click="galleryImg">从相册选取</button>
    <button @click="captureImage">拍照</button>
    <div class="imgBox">
      <img :src="imgSrc">
    </div>
  </div>
</template>
<script>
  export default{
    data(){
      return{
        imgSrc:''//展示的图片路径
      }
    },
    methods:{
// 从相册中选取图片
      galleryImg(){
        let This=this
        console.log("从相册中选择图片:");
        plus.gallery.pick( function(path){//从相册中选择图片
          This.imgSrc=path
          alert(path);
        }, function ( e ) {//取消选择图片
          console.log( "取消选择图片" );
        }, {filter:"image"} );
      },
// 拍照
     captureImage(){
        let This=this
        var cmr = plus.camera.getCamera();//获取摄像头管理对象
        var res = cmr.supportedImageResolutions[0];//字符串数组,摄像头支持的拍照分辨率
        var fmt
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值