当前位置:网站首页>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>边栏推荐
- IEEE TBD SCI影响因子提升至4.271,位列Q1区!
- TFTP download kernel, NFS mount file system
- How to write a technical proposal
- AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
- [BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
- 基于SSH的通讯网络电子计费系统
- Design and principle of tubes responsive data system
- Generate confrontation network, from dcgan to stylegan, pixel2pixel, face generation and image translation.
- Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
- IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
猜你喜欢

Exploration and practice of "flow batch integration" in JD

Word中添加代码块(转载)

Deep understanding of JVM (IV) - garbage collection (I)

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

New skill: accelerate node through code cache JS startup

How to write a technical proposal

Deep understanding of JVM (I) - memory structure (I)
![[Architecture] 1366- how to draw an excellent architecture diagram](/img/98/5dc29e08e91e751f67d910fadc6430.jpg)
[Architecture] 1366- how to draw an excellent architecture diagram

Thinking on large file processing (upload, download)

5g has been in business for three years. Where will innovation go in the future?
随机推荐
基于SSH的客户关系CRM管理系统
Booking UI effect implemented by svg
vue3 响应式数据库—— reactive
Analysis on the construction scheme and necessity of constructing expressway video monitoring platform
Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases
Taishan Office Technology Lecture: how to align and draw words of different sizes on the same line
Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
[binary tree] preorder traversal to construct binary search tree
splitting. JS password display hidden JS effect
Splitting. JS text title slow loading JS effect
Deep understanding of JVM (II) - memory structure (II)
Six pictures show you why TCP has three handshakes?
ABAP-发布Restful服务
联想“双平台”运维解决方案 助力智慧医疗行业智慧管理能力全面提升
MySQL reports that the column timestamp field cannot be null
5g business is officially commercial. What are the opportunities for radio and television?
Development: how to install offline MySQL in Linux system?
Redis (II) -- persistence
[sword finger offer] 52 The first common node of two linked lists
IEEE TBD SCI影响因子提升至4.271,位列Q1区!