在A.wxml 文件中有一个按钮 “从相册中选择”  ,代码如下:

<navigator url="/pages/index/index?guide=1" hover-class="none">

<view class="chooseView">

从相册中选择

</view>

</navigator>


在index.wxml文件中有一个组件,camera。

在index.js文件中的onLoad方法中,获取guide=1,并且把她存在stroge里.。代码如下:

onLoad: function (options) {

    if (options.guide) {

        wx.setStorageSync('guide', 1);

    }

},

在camera组件的ready方法中,进行判断,并且调用chooseImg方法。

ready:function(){

    if (wx.getStorageSync('guide')) {

        this.chooseImg();

        wx.removeStorageSync('guide');

    }

},


camera.js文件的代码如下:


const common = require('../../utils/common.js');

const util = require('../../utils/util.js');

Component({

properties: {

// 这里定义了modal属性,属性值可以在组件使用时指定

outLine: {

type: Object,

value: {},

},

previewPhoto: {

type: Object,

value: {}

},

deviceInfo:{

type:Object,

value:{}

}

},

data: {

// 这里是一些组件内部数据

}

},

ready:function(){

if (wx.getStorageSync('guide')) {

this.chooseImg();

wx.removeStorageSync('guide');

}

},

methods: {//从相册选取照片

chooseImg: function () {

console.log(this);

let that = this;

let outLine = that.data.outLine;

let point = outLine.point;

let previewPhoto = that.data.previewPhoto;

console.log('-----wx.chooseImage  zhiqian ------');

wx.chooseImage({

count: 1,

sizeType: ['compressed'],

sourceType: ['album'],

success: function (res) {

console.log('-----wx.chooseImage  success ------');

previewPhoto[point].original = res.tempFilePaths[0];

that.triggerEvent('buttonEvent', { previewPhoto: previewPhoto, chooseImage: true, tempImagePath: res.tempFilePaths[0] });

outLine.fetching_hasPhoto_viewControl = 2;

that.triggerEvent('buttonEvent', { outLine: outLine });

// setTimeout(function () {

//   that.triggerEvent('buttonEvent', { outLine: outLine })

// }, 100);

展开全部
收起
1回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • Lydia

    7人对此回答表示赞同

    麻烦给个相关的代码片段

    展开
    7
    3回复
    发布于 5年前

    评论(3)

    收起评论

    • 不吃辣条会死星人 2019-01-16 20:57

      你多点击几次,我这边用的就是6.6.7。依然不行。拜托拜托,在试试。谢谢。

      回复
    • Harper 2019-01-18 12:33

      我这边用6.6.7的版本没有复现你的问题,更新下iOS客户端版本看看?

      回复
    • 幼稚鬼 2019-01-20 23:55

      我刚刚写了一个demo,oppoA51可以有选择照片的弹窗,但是苹果机不出现弹窗。https://github.com/DaYuXiaoZhangTaiHou/chooseImg这个是demo源码地址。麻烦看下。

      回复
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部