uniapp常用

1.下载文件带进度提示

<template>

<view>

<button @click="startDownload">下载文件</button>

<progress :percent="progress" stroke-width="3" />

</view>

</template>

<script setup>

import {

ref

} from 'vue';

// 定义进度条数据

const progress = ref(0);

// 下载文件方法

const startDownload = () => {

const downloadTask = uni.downloadFile({

url: "http://localhost:5140/api/File/download", // 替换为你的API地址

success: (res) => {

console.log(res);

if (res.statusCode === 200) {

uni.showToast({

title: "下载成功",

icon: "success",

});

// 打开文件(根据文件类型选择打开方式)

uni.openDocument({

filePath: res.tempFilePath,

showMenu: true,

});

} else {

uni.showToast({

title: "下载失败",

icon: "none",

});

}

},

fail: (err) => {

console.error("下载失败", err);

uni.showToast({

title: "下载失败",

icon: "none",

});

},

});

// 监听下载进度

downloadTask.onProgressUpdate((res) => {

progress.value = res.progress; // 更新进度条

});

};

</script>

<style>

progress {

margin-top: 20px;

}

</style>

相关推荐
REDcker5 分钟前
显示分辨率标准对照详解
前端·网络·分辨率·显示·屏幕
এ慕ོ冬℘゜26 分钟前
前端实战:jQuery 多条件联合搜索(标题模糊查询 + 日历时间段筛选)
前端·javascript·jquery
武子康36 分钟前
Search Console Platform Properties 扩大 SEO 资产边界:从 Page Ranking 到 Topic Coverage(5 类误读边界 + 3 表数据层设计)
前端·人工智能·后端
随心点儿1 小时前
js postMessage 实现跨域发送消息-应用示例
javascript·ecmascript·postmessage
一点一木1 小时前
从60首歌到1个网站:输入你的故事,还你一首歌
前端·github
IT_陈寒2 小时前
Vue这个特性差点让我加班到凌晨,谁懂啊
前端·人工智能·后端
kyriewen3 小时前
我让AI改一个bug——它偷偷动了5个我没让它碰的地方
前端·javascript·ai编程
遇乐的果园3 小时前
前端学习笔记-vue加载渲染优化
前端·笔记·学习
用户985033593284 小时前
OpenLayers 热力图从原理到 Vue 组件一键接入
前端
颜酱4 小时前
01 | 骨架搭建:FastAPI + Vue 跑通第一个 SSE 流式问答
前端·人工智能·后端