当前位置:网站首页>uni-app进阶之自定义【day13】
uni-app进阶之自定义【day13】
2022-06-30 16:43:00 【华为云】
应用自定义showtoast更新版本时,当检测到应用程序的新版本时,需要更新和下载新版本,并显示下载进度条。状态管理模块的实现如下:
开始下载任务
const downloadTask = uni.downloadFile({ url: data.url, // 接口调用成功 success: (downloadResult) => { uni.hideLoading(); if (downloadResult.statusCode === 200) { plus.runtime.install(downloadResult.tempFilePath, { force: false }, function() { plus.runtime.restart(); }, function(e) { console.error('install fail...'); }); } }, // 接口调用失败 fail: (err) => { uni.showToast({ icon:'none', mask:true, title: '安装失败,请重新下载', }); }, // 接口调用结束 complete: () => { downloadTask.offProgressUpdate(); //取消监听加载进度 } }); //监听下载进度 downloadTask.onProgressUpdate(res => { state.percent = res.progress; });console.log(‘下载进度百分比:’ + res.progress); 下载进度百分比
console.log(‘已经下载的数据长度:’ + res.totalBytesWritten); 已经下载的数据长度,单位 Bytes
console.log(‘预期需要下载的数据总长度:’ + res.totalBytesExpectedToWrite); /预期需要下载的数据总长度,单位 Bytes
使用自定义指令结合自定义组件实现视图渲染和控制逻辑,使用vuex实现状态管理。
首先,在main JS中定义全局组件,并在inittoast中向中的Vue原型注册$showtoos。JS以促进全局调用。
// main.jsimport initToast from "@/components/bocft-toast/initToast.js"import showToast from "@/components/bocft-toast/bocft-toast.vue"initToast(Vue);Vue.component('show-toast',showToast);注意:
一个方法不应该有太多的代码,应该及时解耦。对于fro循环,在判断大量流量时,建议使用map foreach REDUCT而不是switch
公共方法的封装需要注释及其参数和参数注释。单一方法具有单一功能和低耦合。常用的方法写在单独的文件中。那些经常使用的可以附加到原型上。不建议将经常使用的部件连接到原型上
接口的使用应单独封装,以保存代码。请求头及其令牌应统一保存,以尽可能保持接口参数的可控性
在uni app中使用异步/等待
当uni app fallback显示时,它将显示网络并不可怕。单击“重试”更改主页文件的响应时间
只要组件安装在project\umodules目录的components目录或Uni中,并且符合components/component name/component name Vue目录结构。它可以直接在页面中使用,无需参考和注册。
示例:组件目录下有一个组件uni Zujian。目录结构为/components/uni zujian/uni zujian Vue,无需注册即可直接在模板中使用
<template> <view> <uni-zujian></uni-zujian><!-- 这里会显示一个五角星,并且点击后会自动亮星 --> </view> </template><script> // 这里不用import引入,也不需要在components内注册uni-list组件。template里就可以直接用 export default { data() { return { } } }</script>边栏推荐
- Redis (III) - transaction
- Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases
- Communication network electronic billing system based on SSH
- Synchronized summary
- [sword finger offer] sword finger offer 53 - ii Missing numbers from 0 to n-1
- Redis (I) - data type
- Optimization of interface display for general kernel upgrade of mobo video management system v3.5.0
- 清华只能排第3?2022软科中国大学AI专业排名发布
- Apache 解析漏洞(CVE-2017-15715)_漏洞复现
- vue3 响应式数据库—— reactive
猜你喜欢

TFTP download kernel, NFS mount file system

Send the injured baby for emergency medical treatment. Didi's driver ran five red lights in a row

Apache 解析漏洞(CVE-2017-15715)_漏洞复现

【网易云信】播放demo构建:无法将参数 1 从“AsyncModalRunner *”转换为“std::nullptr_t”**

Redis (IX) - enterprise level solution (II)

基于eNSP的校园网设计的仿真模拟

Splitting. JS text title slow loading JS effect

MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等

ABAP publish restful service

Share 5 commonly used feature selection methods, and you must see them when you get started with machine learning!!!
随机推荐
Analysis on the construction scheme and necessity of constructing expressway video monitoring platform
New skill: accelerate node through code cache JS startup
【剑指Offer】52. 两个链表的第一个公共节点
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
Solution: STM32 failed to parse data using cjson
Post office - post office issues (dynamic planning)
splitting. JS password display hidden JS effect
Customer relationship CRM management system based on SSH
Development: how to install offline MySQL in Linux system?
Daily interview 1 question - basic interview question of blue team - emergency response (1) basic idea process of emergency response +windows intrusion screening idea
【机器学习】K-means聚类分析
NFT: 开启加密艺术时代的无限可能
Redis (VIII) - enterprise level solution (I)
大文件处理(上传,下载)思考
What will be the game changes brought about by the meta universe?
【剑指Offer】53 - I. 在排序数组中查找数字 I
Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases
Lenovo's "dual platform" operation and maintenance solution helps to comprehensively improve the intelligent management ability of the intelligent medical industry
[sword finger offer] sword finger offer 53 - ii Missing numbers from 0 to n-1