In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the problems encountered in the development of Android Mini Program?" in the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Wrap the list with block when rendering the list
{{index}}: {{item}}
Block is not actually rendered on the page, only as a wrapper element and accepts control attributes
Write a custom component
Custom components are divided into four parts
Properties received by the properties component
Properties: {/ / default prompt for input box placeholder: {type: String, / / Type of attribute value value:''/ / attribute default}}
Data component data
Methods component method. Generally, internal methods start with _
The lifecycle function of a component, which usually uses ready and is executed after the component layout is completed, and the node information can be obtained (using SelectorQuery)
Call the method passed in by the parent component
/ / subcomponent var myEventDetail = {value:''}; / / detail object, which is provided to the event listener function and writes the option this.triggerEvent ('onclear', myEventDetail, myEventOption) / / parent component onSearch (e) {console.log (e.detail.value)} that needs to be passed to the external data this.triggerEvent = {} / / triggering the event.
The method of calling child components directly by parent components
/ / parent component, use selectComponent to get the instance of the child component, and directly call the method let searchBar = this.selectComponent ('# search-bar'); searchBar.setData ({value: e.currentTarget.dataset.name}) searchBar.onClickSearch ({detail: {value: e.currentTarget.dataset.name}})
Get the width and height of dom in the subcomponent
/ / get the screen width let windowWidth = wx.getSystemInfoSync (). WindowWidth// needs to write thislet query = wx.createSelectorQuery () .in (this) inside the component; let that = this;query.selectAll ('.tagItem') .boundingClientRect () query.exec (function (res) {let allWidth = 0 Res [0] .map (item= > {allWidth = allWidth + item.width return allWidth}) let length = res [0] .length let ratioWidth = allWidth / windowWidth that.setData ({allLength: length, iphone: ratioWidth + (length = = 1? 0: res [0] .length})})
OnLoad will not be called when the page returns
Previously, the part of the calling API was written into the onLoad. Enter the details page from the article list, and click on the upper left corner of the details page to return to the list page. The readings of the list page should be updated, but not updated, because the article list API has not been reset.
So write the part of the article list interface in onShow.
Custom tabbar optimization
For the first time, change the tabbar encapsulated by the component into the template form of the page
1. Before, it was written in the form of components, and the icons on template;tabbar were changed to iconfont, which solved the problem of flash when clicking on tabbar.
{{item.text}} {{tabbar.num > 99?'99 percent': tabbar.num}
2. When you click tabbar, you need to destroy the previous page and jump to the page that needs to be redirected, so reLaunch is used in the navigator component.
In the second optimization, all the pages with tabbar are encapsulated into components and written on the page, where setData switches tab
Changes made:
Pages with tabbar are rewritten as components
Because only the ready method is mounted in the component, the onShow,onReachBottom,onPullDownRefresh in the previous page is called by the parent page.
OnPullDownRefresh: function () {if (this.data.tabbarID = this.data.tabbarList.article) {/ / use selectComponent to find the component instance and call the internal method let articlePage = this.selectComponent ('# article-page'); articlePage.onPullDownRefresh ();} else if (this.data.tabbarID = this.data.tabbarList.doctor) {let doctorPage = this.selectComponent ('# doctor-page') DoctorPage.onPullDownRefresh ();} else {wx.stopPullDownRefresh ();}}
The problems brought about:
Every tabbar has the effect of a drop-down refresh, even if it is not required.
There may be a problem when you click a button from another page and jump directly to a tab card on the front page.
Use iconfont
Log in to iconfont.cn to download the zip package
Unzip the .ttf file and convert it to base64 format on transfonter.org/
Write style.css to the newly created iconfont.wxss, and replace the font file path with the newly converted base64.
Import iconfont.wxss in app.wxss
Note: the style in the component itself is not affected by app.wxss, so when you need to use iconfont in the component, you need to manually quote app.wxss or iconfont.wxss.
Left sliding effect of the list
1. Bind the event on the parent element of the list
List-container {position: relative; width:100%; height: 224rpx; overflow: hidden;}. List-item {position: absolute; left: 0; z-index: 5; transition: left 0.2s ease-in-out; background-color: # fff } .backCover {box-sizing: border-box; width: 200rpx; height: 218rpx; position: absolute; right: 0; top: 0; z-index: 4;}
2. Modify the left value of the list item by judging the sliding distance
OnTouchStartListItem: function (e) {/ / is a single-finger touch if (e.touches.length = 1) {/ / write down the x-axis position of the contact point from the edge of the screen this.setData ({startX: e.touches [0] .clientX,})}} OnTouchMoveListItem: function (e) {var that = this if (e.touches.length = = 1) {var disX = that.data.startX-e.touches [0] .clientX Var deleteBtnWidth = that.data.deleteBtnWidth; var txtStyle = ""; if (disX
< deleteBtnWidth / 4) { txtStyle = "left:0rpx"; } else { txtStyle = "left:-" + deleteBtnWidth + "rpx"; } var index = e.currentTarget.id var list = that.data.doctorList.list list[index].txtStyle = txtStyle; that.setData({ doctorList: { list: list, total: that.data.doctorList.total } }) }}, onTouchEndListItem: function (e) { var that = this if (e.changedTouches.length == 1) { var endX = e.changedTouches[0].clientX; var disX = that.data.startX - endX; var deleteBtnWidth = that.data.deleteBtnWidth; var txtStyle = disX >DeleteBtnWidth / 2? "left:-" + deleteBtnWidth + "px": "left:0px"; var index = e.currentTarget.id var list = that.data.doctorList.list list [index] .txtStyle = txtStyle That.setData ({doctorList: {list: list, total: that.data.doctorList.total}}) }}, this is the end of the content of "what are the problems encountered in the development of Android Mini Program?" thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.