This article brings you relevant knowledge about WeChat Mini Program. It mainly introduces some common interview questions, including how to obtain user information in the Mini Program and how to use the Mini Program. To implement parent-child component passing parameters, let’s take a look at it. I hope it will be helpful to everyone.
[Related learning recommendations: 小program learning tutorial]
(1) Before the upgrade, the mini program can use wx.getUserInfo to directly obtain user information. This method is gradually no longer available.
(2.) After the upgrade, you can use the following method to obtain it. User's account information:
(1) Use button and set its attributes: open-type="getUserInfo"
Send to friends: onShareAppMessage(Object object);
Share to Moments: onShareTimeline();
Restrictions:
"Single page mode" Below, some components or interfaces have certain restrictions:
1. The page has no login status, and login-related interfaces and wx.login() are not available;
2. Jumps are not allowed Go to other pages, including jumping to mini program pages, jumping to other mini programs, and jumping to WeChat native pages;
3. Horizontal screen is not allowed, and the tabbars contained in the page will not be rendered, including custom tabbars;
4. Local storage is not shared with the normal mode of the mini program;
(1) Find the project in the WeChat web developer tool and set the domain name of the server. If your mini program does not use external network requests, you do not need to configure the server. After configuring the server, preview it first to see if there are any problems. If there are no problems, click Upload.
(2) After uploading the code, log in to the WeChat mini program backend on the WeChat official account platform, click Development Management, you can see the code you just uploaded, click Submit for review, and that's it. The next step is to wait for WeChat’s official review.
(3) It usually takes about 1 to 3 days
(1) Open cmd, enter your project, execute: npm init in cmd, initialize the project
(2) Then install Vant
(3) Open On the mini program client, select the [Tools] menu -> select the [Build npm] command
1. Parent component passes parameters to child components Value
Define properties in the child component
properties: { // 复杂定义 name:{ type: String, value:'张三丰' }, // 简单定义 name2:String},
The parent component passes the value to the child component by setting properties when referencing the child component
2. The child component passes the value to the parent component Component passing value
Bind a custom event in the component
// 引用了自定义的组件, 绑定了myevent事件,这个事件对应的是parentEvent方法 <test-button name="张无忌" bindmyevent="parentEvent"></test-button>
Trigger this event in the child component, and you can pass the value to the parent component.
The event is triggered through triggerEvent in the subcomponent
methods: { 方法名字: function(){ var myEventDetail = {} // detail对象,提供给事件监听函数 var myEventOption = {} // 触发事件的选项 this.triggerEvent('myevent', myEventDetail, myEventOption) } }
onLaunch(options)
Called when the applet is loaded. This method is generally used to do some initialization things. For example, obtain user information, obtain historical cache information, obtain applet opening sources, etc.
onShow(options)
Called when the applet is started, or when it enters the foreground display from the background. If you want to perform something every time the mini program enters the foreground, you can put the code in this. For example, some data that changes dynamically in real time needs to be updated from the server every time the user comes in, so we can do it in this.
onHide()
The mini program is switched to the background (including when WeChat itself is switched to the background or the mini program is temporarily switched to the background). You can save some data in this method.
onError(String error)
Triggered when a script error occurs in the applet or the api call fails. When an error occurs in the mini program, the error information will be sent to this function, so you can do some error collection in this function.
onPageNotFound(Object)
Triggered when the page to be opened by the applet does not exist. Generally, when the code is updated, some pages are deleted, but this happens when other places have not been changed, or some event pages are closed after the event. You can also do some error collection and page re-jumping in this.
getApp()
Get the current app object. Generally called outside app.js. You can use this inside app.js to get the current large object; when you want to use global data defined in app.js outside, you need to use getApp().
OnLoad(), onReady(), onShow(), onHide(), and onUnload() are five page life cycle functions, which are called when the page is loaded, ready, rendered, hidden, and unloaded.
When binding an event in a mini program, you can start with bind and then follow the event type. For example, bindtap binds a click event, and the corresponding value is a string. You need to define a function with the same name in the page constructor. Each time an event is triggered, the content of the corresponding function will be executed.
In addition to bind, event binding can also be done through catch in the mini program. Events bound through catch will not trigger event bubbling.
Event triggering is divided into two stages, the first is the capture stage, and the second is the bubbling stage. By default, events are triggered in the bubbling phase. If you want the event to be triggered during the capture phase, you can bind the event through capture-bind.
[Related learning recommendations: 小program learning tutorial]
The above is the detailed content of Summarize and share common interview questions on WeChat mini programs. For more information, please follow other related articles on the PHP Chinese website!