组件内调用wx.chooseImage方法 iphoneX 不生效
发布于 5 年前 作者 mayong 3032 次浏览 来自 问答

在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);

},

fail:function(res){

console.log(’-----wx.chooseImage  fail ------’);

},

complete: function (res) {

console.log(’-----wx.chooseImage  complete ------’);

}

})

},

问题是:程序在电脑上测试没问题,oppoA51真机 没问题   iphone7 没问题    但是iphoneX  console.log(’-----wx.chooseImage  zhiqian ------’);到这一步就不执行了。有时候会执行  偶然事件。

------------------  end ----------------


2 回复

楼主解决了吗,我遇到iphonex多次出现,上传图片不成功

回到顶部