当前位置:网站首页>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>边栏推荐
- Small tools (3) integration knife4j3.0.3 interface document
- The gates of Europe
- The company was jailed for nonstandard bug during the test ~ [cartoon version]
- 如何写一个技术方案
- Php8.0 environment detailed installation tutorial
- MySQL advanced - Architecture
- Deep understanding of JVM (IV) - garbage collection (I)
- LRN local response normalization
- Spin lock exploration
- Conception d'un centre commercial en ligne basé sur SSH
猜你喜欢

How to write a technical proposal

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

IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
![[Netease Yunxin] playback demo build: unable to convert parameter 1 from](/img/6e/41e1eafd4c863c9e5f3a545b69a257.png)
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**

Daily interview 1 question - how to prevent CDN protection from being bypassed

腾讯持久化框架MMKV原理探究

MySQL advanced - Architecture

墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路

基於SSH的網上商城設計

Generate confrontation network, from dcgan to stylegan, pixel2pixel, face generation and image translation.
随机推荐
[Architecture] 1366- how to draw an excellent architecture diagram
Only black-and-white box test is required for test opening post? No, but also learn performance test
[sword finger offer] 53 - I. find the number I in the sorted array
Advanced Mathematics (Seventh Edition) Tongji University General exercises one person solution
ASP. Net authentication code login
If you want to learn software testing, you must see series, 2022 software testing engineer's career development
Radio and television 5g officially set sail, attracting attention on how to apply the golden band
AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
Daily interview 1 question - how to prevent CDN protection from being bypassed
Spin lock exploration
Building a basic buildreoot file system
Word中添加代码块(转载)
K-line diagram interpretation and practical application skills (see position entry)
MSF后渗透总结
[zero basic IOT pwn] environment construction
Small Tools(3) 集成Knife4j3.0.3接口文档
MySQL advanced - index optimization (super detailed)
力扣解法汇总1175-质数排列
ABAP publish restful service
Distributed machine learning: model average Ma and elastic average easgd (pyspark)