图片上传
Demo
使用FileReader
方法,选择图片后读取到base64
格式的图片信息,通过赋值给img
的src
实现图片预览
vue
<template>
<uploadImg v-model="imgurl"></uploadImg>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import uploadImg from './uploadImg/uploadImg.vue'
const imgurl = ref('')
</script>
Props
参数 | 类型 | 说明 |
---|---|---|
v-model | any | 图片路径或对象 |
max | number | 图片大小限制,默认500k |
tip | string | 仅支持jpg,png,gif文件 |