一 点睛
1 官网
http://uniapp.dcloud.io/platform?id=%E8%B7%A8%E7%AB%AF%E5%85%BC%E5%AE%B9
二 代码
1 修改 phone.vue
<template>
<view>
<button type="primary" @click="updatePhoto">上传图片</button>
<image v-for="item in imgArr" :src="item" @click="previewImg(item)"></image>
<!-- #ifdef H5 -->
<view>在H5中可见</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view>在微信小程序中可见</view>
<!-- #endif -->
</view>
</template>
<script>
export default {
data() {
return {
imgArr: []
}
},
methods: {
updatePhoto() {
uni.chooseImage({
count: 5, //默认9
success: res => {
this.imgArr = res.tempFilePaths
}
});
},
previewImg(current) {
uni.previewImage({
current: current,
urls: this.imgArr,
loop: true,
indicator: 'number'
})
}
},
onLoad() {
// #ifdef H5
console.log('在h5中打印')
// #endif
// #ifdef MP-WEIXIN
console.log('在微信小程序中打印')
// #endif
}
}
</script>
<style>
/* h5中的样式 */
/* #ifdef H5 */
view {
color: #0000FF;
}
/* #endif */
/* 微信小程序样式 */
/* #ifdef MP-WEIXIN */
view {
color: #008000;
}
/* #endif */
</style>
三 效果
1 H5条件编译效果
2 微信小程序编译效果
来源:oschina
链接:https://my.oschina.net/u/4269898/blog/4557531