1. Development ideas
Anyone who has done app development knows that the boot page needs to use local storage. The first time the user installs the user, a data will be stored when they click to enter the homepage. Then the idea of WeChat applet is the same. You can set a startup page every time When the applet is opened, the startup page will be loaded, and the stored data can be verified at startup. If the data is stored, it means that there is no need to open the guide page again and go directly to the home page.
Second, the specific implementation process
1. Create a new startup page
Add a new startup page to app.json and generate the corresponding folder and file under pages after saving
My startup page here is the white page
This page can be a whiteboard or loading animation or something similar to welcome
2. Set the startup jump code
Detect data in local storage when the interface is loaded
Use wx.setStorageSync('welcome',true); for storage
Use wx.getStorageSync('welcome'); to get storage data
/**
* 生命周期函数--监听页面加载
*/
onLoad: function() {
const welecome = wx.getStorageSync('welcome');
if (welecome) {
console.log(welecome);
wx.redirectTo({
url: "../index/index",
})
} else {
wx.navigateTo({
url: "../welcome/welcome",
})
}
},
3. Implementation of the guide page
Create a new welcome interface and place a button that clicks to jump in the interface
In welcome.wxml
<view class='journey-container' bindtap='onBindTap'>
<text class='journey'>开启就业之旅</text>
</view>
welcome.js
/**
* 点击开启就业之旅
*/
onBindTap: function() {
wx.setStorageSync('welcome',true);
wx.navigateTo({
url: '../index/index',
})
},
The above content saw the time to save data.
The above is the realization of the guide page in the mini program.
Another way is to implement in onLaunch of app.js, but there is a problem that onLaunch will appear, and the interface will be displayed first and then jump.