当前位置:网站首页>Advanced customization of uni app [day13]
Advanced customization of uni app [day13]
2022-06-30 18:12:00 【Hua Weiyun】
Apply custom showtoast When updating the version , When a new version of the application is detected , Need to update and download new version , And display the download progress bar . The implementation of the state management module is as follows :
Start downloading tasks
const downloadTask = uni.downloadFile({ url: data.url, // Interface call successful 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...'); }); } }, // Interface call failed fail: (err) => { uni.showToast({ icon:'none', mask:true, title: ' Installation failed , Please download again ', }); }, // End of interface call complete: () => { downloadTask.offProgressUpdate(); // Cancel listening to loading progress } }); // Monitor download progress downloadTask.onProgressUpdate(res => { state.percent = res.progress; });console.log(‘ Download progress percentage :’ + res.progress); Download progress percentage
console.log(‘ The length of downloaded data :’ + res.totalBytesWritten); The length of downloaded data , Company Bytes
console.log(‘ The total length of data that is expected to be downloaded :’ + res.totalBytesExpectedToWrite); / The total length of data that is expected to be downloaded , Company Bytes
The view rendering and control logic are realized by using custom instructions and custom components , Use vuex Realize state management .
First , stay main JS Define global components in , And in inittoast Middle to middle Vue Prototype registration $showtoos.JS To facilitate global invocation .
// 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); Be careful :
A method should not have too much code , It should be decoupled in time . about fro loop , When judging a large amount of traffic , It is recommended to use map foreach REDUCT instead of switch
The encapsulation of public methods requires annotations and their parameters and parameter annotations . A single method has a single function and low coupling . Common methods are written in separate files . Those that are often used can be attached to the prototype . It is not recommended to connect frequently used parts to prototypes
The use of interfaces shall be encapsulated separately , To save the code . The request header and its token should be saved uniformly , To maintain the controllability of interface parameters as much as possible
stay uni app Use asynchronous in / wait for
When uni app fallback Display time , It will show that the Internet is not terrible . single click “ retry ” Change the response time of the home page file
As long as the components are installed in project\umodules The directory components Directory or Uni in , And in accordance with components/component name/component name Vue Directory structure . It can be used directly in the page , No reference and registration required .
Example : There is a component in the component directory uni Zujian. The directory structure is /components/uni zujian/uni zujian Vue, You can use it directly in the template without registration
<template> <view> <uni-zujian></uni-zujian><!-- A five pointed star will be displayed here , And the star will automatically light up after clicking --> </view> </template><script> // Here there is no import introduce , It doesn't need to be in components Internal registration uni-list Components .template You can use it directly in the library export default { data() { return { } } }</script>边栏推荐
- 5g has been in business for three years. Where will innovation go in the future?
- LRN local response normalization
- Unity开发bug记录100例子(第1例)——打包后shader失效或者bug
- [Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**
- 如何写一个技术方案
- Dropout: immediate deactivation
- Elastic 8.0: opening a new era of speed, scale, relevance and simplicity
- Small Tools(3) 集成Knife4j3.0.3接口文档
- Generate confrontation network, from dcgan to stylegan, pixel2pixel, face generation and image translation.
- The company was jailed for nonstandard bug during the test ~ [cartoon version]
猜你喜欢

Alexnet of CNN classic network (Theory)

Talk about the SQL server version of DTM sub transaction barrier function

It's not easy to say I love you | use the minimum web API to upload files

What does software testing need to learn? Test learning outline sorting

Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole

ASP. Net authentication code login

又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队

Daily interview 1 question - basic interview question of blue team - emergency response (1) basic idea process of emergency response +windows intrusion screening idea

基于SSH的客户关系CRM管理系统

2022上半年盘点:20+主流数据库重大更新及技术要点汇总
随机推荐
Thinking on large file processing (upload, download)
Redis (V) - advanced data types
Apache 解析漏洞(CVE-2017-15715)_漏洞复现
基于SSH的网上商城设计
Post penetration file system + uploading and downloading files
Elastic 8.0: opening a new era of speed, scale, relevance and simplicity
VS code 树视图 treeView
Post office - post office issues (dynamic planning)
News management system based on SSM
LRN local response normalization
每日面试1题-如何防止CDN防护被绕过
[BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
Redis (IX) - enterprise level solution (II)
Radio and television 5g officially set sail, attracting attention on how to apply the golden band
100 examples of bug records of unity development (the first example) -- shader failure or bug after packaging
Is there an optimal solution to the energy consumption anxiety in the data center?
IEEE TBD SCI影响因子提升至4.271,位列Q1区!
One script of unity actual combat realizes radar chart
Development details of NFT casting trading platform
MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc