zoukankan      html  css  js  c++  java
  • 微信相机


    调用微信相机
    首先要在index.html 中引入 微信封装好的原生调用相机的js
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript" charset="utf-8"></script>
    然后从后台获取配置参数 四项

    后台会给你一个地址 返回给你的参数
    wx.config({
    debug:false,
    appId:res.data.appid,
    timestamp:res.data.timestamp,
    nonceStr:res.data.nonceStr,
    signature:res.data.signature
    jsApiList:['chooseImage','uploadImage'] //功能列表、我们要使用js-sdk 的什么功能
    })
    选择图片
    wx.chooseImage({
    count:9,//默认9
    sizeType:['original','compressed'],//可以指定是原图还是压缩图,默认二者都有
    sourceType:['album','camera'],//可以指定来源是相册还是相机,默认二者都有
    success:function(res){
    if(that.imgList.length + res.localIds.length > 9){
    api.toastDiv('最多上传9张图片')
    }else{
    that.imgList = that.imgList.concat(res.localIds);//返回选定照片的本地ID列表
    if(that.imgList.length >= 9){that.showAddpic = false}
    }

    })
    本地渲染 直接把id 赋值上去即可
    <li v-for="(it,key) in imgList" :key = "key">
    <img :src="it" alr="">
    </li>

    上传微信服务器 拿下下载的地址

    wx.uploadImage({
    localId:this.imgList[i],//需要上传的图片的本地id
    isShowProgressTips:1,//默认为1,显示进度提示
    success:function(res){
    返回回来的url 返回给后台
    })

    注意 需要现在vue  安装 

    import wx from 'weixin-js-sdk'    引入
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  • 相关阅读:
    C++学习笔记27,虚函数作品
    HDU
    POJ 2524 Ubiquitous Religions
    HDU-3839-Ancient Messages(DFS)
    thinkphp 删除所有缓存 Rumtime 以及 Html 静态缓存
    [AngularJS] Design Pattern: Simple Mediator
    [Javascript] Add a browser build to an npm module
    [Angular 2] ngrx/store
    [Typescript] Introduction to Generics in Typescript
    [AngularJS] angular-md-table for Angular material design
  • 原文地址:https://www.cnblogs.com/shejuan/p/8085324.html
Copyright © 2011-2022 走看看