1. 程式人生 > 實用技巧 >uni-app-上傳圖片、圖片預覽

uni-app-上傳圖片、圖片預覽

官方文件

uni.chooseImage(OBJECT)圖片上傳

uni.previewImage(OBJECT)圖片預覽

<template>
    <view>
        <button type="primary" @click="upload">上傳圖片</button>
        <image v-for="item in img_arr" :src="item" @click="preview(item)"></image>
    </view>
</template>

<script>
    export 
default { data() { return { img_arr: [] } }, methods: { upload() { // let this_ = this uni.chooseImage({ success: res => { this.img_arr = res.tempFilePaths console.log(
this.img_arr) } }) }, preview(current){ uni.previewImage({ current, urls:this.img_arr, indicator:'number', loop:true, success() { console.log(
"成功") } }) } } } </script> <style> </style>