当前位置:网站首页>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>
边栏推荐
- 【剑指Offer】剑指 Offer 53 - II. 0~n-1中缺失的数字
- Canvas mouse control gravity JS effect
- Fragmentary knowledge points of MySQL
- Grep output with multiple colors- Grep output with multiple Colors?
- . Net ORM framework hisql practice - Chapter 1 - integrating hisql
- 6 張圖帶你搞懂 TCP 為什麼是三次握手?
- 基于eNSP的校园网设计的仿真模拟
- Partition marble (multiple knapsack + binary optimization)
- NFT: 开启加密艺术时代的无限可能
- Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
猜你喜欢
Exploration and practice of "flow batch integration" in JD
New skill: accelerate node through code cache JS startup
Design of online shopping mall based on SSH
IEEE TBD SCI影响因子提升至4.271,位列Q1区!
编译生成busybox文件系统
Daily interview 1 question - how to prevent CDN protection from being bypassed
TFTP download kernel, NFS mount file system
What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo
Share 5 commonly used feature selection methods, and you must see them when you get started with machine learning!!!
每日面试1题-如何防止CDN防护被绕过
随机推荐
[sword finger offer] 53 - I. find the number I in the sorted array
Advanced Mathematics (Seventh Edition) Tongji University General exercises one person solution
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**
墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
Ardunio esp32 DH11 real time uploading temperature and humidity Alibaba cloud self built mqtt
港科大&MSRA新研究:关于图像到图像转换,Finetuning is all you need
K-line diagram interpretation and practical application skills (see position entry)
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, is building an open source ecological road
构建基本buildroot文件系统
[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection
Shortcut keys for the rainbow brackets plug-in
Deep understanding of JVM (I) - memory structure (I)
Redis (III) - transaction
MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等
编译生成busybox文件系统
[binary tree] preorder traversal to construct binary search tree
The secondary menu of the magic article system v5.4.0 supports the optimization of form display
Tubes响应性数据系统的设计与原理
Add code block in word (Reprint)
Ardunio esp32 obtains real-time temperature and humidity in mqtt protocol (DH11)