Home  >  Article  >  WeChat Applet  >  Summarize and share common interview questions on WeChat mini programs

Summarize and share common interview questions on WeChat mini programs

WBOY
WBOYforward
2022-05-09 17:36:288132browse

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.

Summarize and share common interview questions on WeChat mini programs

[Related learning recommendations: 小program learning tutorial]

1. How to obtain user information in a mini program?

(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" 077b88389be1f66228183442eccca59dGet user information65281c5ac262bf6d81768915a4a77ac0

2. How to implement the sharing function in the mini program? What are the restrictions on WeChat?

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;

3. How did your mini program go online, and how long does it take to review it?

(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

4. How to use third-party components like Vant in the mini program?

(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

5. How does the mini program implement parent-child component passing parameters?

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(&#39;myevent&#39;, myEventDetail, myEventOption)    }  }

6. What are the life cycles of the APP in the mini program?

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().

7. What are the life cycles of Pages in mini programs?

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.

8. How does the mini program define events?

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.

9. How to prevent events from mini programs from bubbling up?

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.

10. How to make the event trigger during the capture phase?

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete