3830关注11701浏览
在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);
-
至过去的我
2044人对此回答表示赞同
我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多> -
Lydia
7人对此回答表示赞同
麻烦给个相关的代码片段
展开73回复分享发布于 6年前评论(3)
收起评论
你多点击几次,我这边用的就是6.6.7。依然不行。拜托拜托,在试试。谢谢。
我这边用6.6.7的版本没有复现你的问题,更新下iOS客户端版本看看?
我刚刚写了一个demo,oppoA51可以有选择照片的弹窗,但是苹果机不出现弹窗。https://github.com/DaYuXiaoZhangTaiHou/chooseImg这个是demo源码地址。麻烦看下。