<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@next/dist/vant.min.css"> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/vant@next/dist/vant.min.js"></script>
import { createApp } from 'vue' import App from './App.vue' import Vant from 'vant' import 'vant/lib/index.css' createApp(App).use(Vant).mount('#app')
<template> <van-image-uploader v-model="images" multiple max-count="9" :after-read="afterRead" /> </template> <script> export default { data() { return { images: [] } }, methods: { afterRead(file) { // 上传文件后的回调函数 console.log(file) } } } </script>
afterRead(file) { const formData = new FormData() formData.append('file', file.file) // 调用接口上传文件 axios.post('/upload', formData) .then(response => { // 处理上传成功逻辑 console.log(response) }) .catch(error => { // 处理上传失败逻辑 console.error(error) }) }
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com