文章目录
选择图片预览图片(全屏显示图片)案例——选择图片,然后预览
选择图片
参考 wx.chooseImage
uni
.chooseImage({
count
: 1,
sizeType
: ['original', 'compressed'],
sourceType
: ['album', 'camera'],
success(res
) {
console
.log(res
)
const tempFilePaths
= res
.tempFilePaths
;
result
.originUrl
= tempFilePaths
[0];
uni
.getImageInfo({
src
: res
.tempFilePaths
[0],
success(res
) {
var originWidth
, originHeight
;
originHeight
= res
.height
;
originWidth
= res
.width
;
}
})
}
})
预览图片(全屏显示图片)
参考 wx.previewImage
uni
.previewImage({
current
: current
,
urls
: [current
]
})
案例——选择图片,然后预览
<template>
<view class="avatar-image">
<image :src="uploadImageUrl" :data-src="uploadImageUrl" mode="widthFix" @tap="chooseVisitorImageAction" @longtap="previewImageAction"
v-if="uploadImageUrl != ''"></image>
<image class="img" src="/static/images/camera_normal.png" mode="widthFix" @tap="chooseVisitorImageAction" v-if="uploadImageUrl == ''"></image>
<view class="text-center tip">
{{tips}}
</view>
</view>
</template>
<script>
export default {
data: function() {
return {
tips: '上传人脸正面照',
uploadImageUrl: ''
}
},
props: {
imgUrl: {
type: String,
default: ''
}
},
mounted: function () {
this.uploadImageUrl = this.imgUrl;
},
methods: {
previewImageAction: function(eventObj) {
const current = eventObj.target.dataset.src;
debugger
uni.previewImage({
current: current,
urls: [current]
})
},
chooseVisitorImageAction: function() {
const that = this;
uni.chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success: function(res) {
that.$emit("change", res.tempFilePaths[0]);
that.uploadImageUrl = res.tempFilePaths[0];
}
})
}
},
watch: {
imgUrl: function (newValue, oldValue) {
debugger
this.uploadImageUrl = newValue;
}
}
}
</script>
<style lang="scss">
.avatar-image {
width: 33%;
max-width: 300px;
margin: 0 auto;
image {
width: 100%;
height: auto;
}
.tip {
line-height: 50px;
;
}
}
</style>
转载请注明原文地址: https://mac.8miu.com/read-496470.html