惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
宝玉的分享
宝玉的分享
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
V
Visual Studio Blog
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
P
Proofpoint News Feed
L
LangChain Blog
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】
Martin Fowler
Martin Fowler

博客园 - Insus.NET

拖放式上传 实现MultipartStreamProvider经Web API上传文档或图片 文件上传和表单字段混合提交 在HttpContext.Current返回null时如何操作 angularjs根据类型动态加载组件 angularjs获取数据服务 扫一扫直连WiFi二维码 User Profile Service 服务未能登录 Visual Studio2026创建Vue项目 安装与配置node.js HTTP Error 403.14 - Forbidden VisualStudio2026回滚上一版本 消息认证码(加强) 网站无法使用插值字符串语法 HMAC(Hash-based Message Authentication Code)认证示例 浏览器自动发送域凭据 企业内小网站兼用Windows验证登录 访问用户控件的函数 onblur事件改为监听处理 将警报消息改为吐司消息 内容有无变化OnBlur即时更新引起的问题与解决 混合式提高用户编辑与操作效率 光标离开文框后即刻更新 WebForm实现Web API JavaScript对GridView删除行后并重新给其数据绑定 把CS值传给JS使用 v2 确认信息confirm由C#后端移至javascript前端 无法发布网站Web Site JavaScript判断字符是否为decimal 点击单元格弹出窗口处理数据返回父页
Vue3实现拖放式上传
Insus.NET · 2026-09-13 · via 博客园 - Insus.NET
 <%--<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>--%>
 <script src="../../Scripts/vue.global.js"></script>

 <%--<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>--%>
 <script src="../../Scripts/axios.min.js"></script>

Html markup,
2026-09-13_16-06-44

<div style="margin-top: 3px;">
    <div id="app">
        <div v-if="loading">加载中...</div>
        <div v-else-if="error">{{ error }}</div>
        
        <%--把前一篇的html markup 拉到这里来。--%>
        <%--如果你有实现过前一篇,添加外层vue3代码特征即可。--%>
    </div>
</div>

View Code

 
Vue3 javascript,
2026-09-13_17-24-18

展开标志A,
2026-09-13_17-28-00

const uploadFile = async (file) => {
    if (!file) {
        alert('没有选择文件');
        return;
    }

    const url = '/api/ul/UploadImage';
    const payload = new FormData();
    payload.append("file", file);

    try {
        const response = await axios.post(url, payload, {
            headers: { 'Content-Type': 'multipart/form-data' }
        });

        const data = response.data;
        if (data.Status) {
            alert(data.Message);
        } else {
            alert(data.Message || '上传失败');
        }
    } catch (error) {
        console.error('Error uploading file:', error);
        alert('上传失败,请重试');
    }
};

View Code

展开标志B,
2026-09-13_17-31-15

onMounted(() => {
    // 绑定上传事件
    const dropZone = document.getElementById('dropZone');
    const fileInput = document.getElementById('FileImage');
    const uploadButton = document.getElementById('Button_Upload');
    const urlInput = document.getElementById('ImageUrl');
    const urlButton = document.getElementById('Button_UploadUrl');

    // 点击上传
    uploadButton.addEventListener('click', () => {
        if (fileInput.files.length === 0) {
            alert('请先选择图片');
            return;
        }
        uploadFile(fileInput.files[0]);
        fileInput.value = '';
    });

    // 拖放上传
    dropZone.addEventListener('dragover', (e) => {
        e.preventDefault();
        dropZone.classList.add('dragover');
    });

    dropZone.addEventListener('dragleave', (e) => {
        e.preventDefault();
        dropZone.classList.remove('dragover');
    });

    dropZone.addEventListener('drop', (e) => {
        e.preventDefault();
        dropZone.classList.remove('dragover');
        const file = e.dataTransfer.files[0];
        if (file) {
            uploadFile(file);
        } else {
            alert('请拖入图片文件');
        }
    });

    // URL上传
    urlButton.addEventListener('click', async () => {
        const imageUrl = urlInput.value.trim();
        if (!imageUrl) {
            alert('请输入图片链接');
            return;
        }

        try {
            const response = await fetch(imageUrl);
            if (!response.ok) throw new Error('获取图片失败');
            const blob = await response.blob();
            const file = new File([blob], 'image_from_url.jpg', {
                type: blob.type || 'image/jpeg'
            });
            await uploadFile(file);
            urlInput.value = '';
        } catch (err) {
            alert('无法下载图片,请检查链接或跨域策略');
            urlInput.value = '';
        }
    });
});

View Code

vue与html + javascript代码相似。懂得语法与规范即可。