Home > Article > Web Front-end > How to jump to the mall from the uniAPP login page
In today's mobile Internet era, the rise of APP has become a trend, and many people use APP to facilitate their lives. For developers, it is very important to choose a good development tool. uniAPP is the first choice of many APP developers. It supports the development of multiple platforms, is easy to use, and has complete functions. However, developers will encounter some problems when using uniAPP to develop APPs, such as how to make the login page jump to the mall page. In this article, we will briefly introduce how uniAPP implements the function of logging in and jumping to the mall.
1. How to implement login jump to the mall
The principle of realizing login jump to the mall page in uniAPP is to use Vue Routing is implemented by triggering jump events based on user events, and then deciding which page to jump to based on routing.
First we add a button to jump to the mall on the login page. When the user clicks the button, perform the following operations:
(1) First, you need to introduce Vue’s routing module. Can be introduced in the main.js file:
import Router from 'vue-router';
Vue.use(Router);
(2) In the router folder Create an index.js file to define routes.
(3) In the index.js file, create a route, set the path attribute to "/mall", and the component attribute to the component name of the mall page.
const router = new Router({
routes: [
{
path: '/mall',
name: 'mall',
component: Mall
}
]
});
(4) Introduced in the login page Vue-router module, and use the $router.push() method to jump to the mall.
<script></p> <p>export default {</p> <p>methods: {</p> <p>toMall() {</p> <p>this.$router.push('/mall');</p> <p>}</p> <p>}</p> <p>}</p> <p></script>
2. How to receive parameters on the mall page
When the login page jumps to the mall, you may need to bring some parameters. At this time, you can pass parameters in the jump address and receive parameters in the mall page. The specific implementation method is as follows:
(1) Pass parameters when jumping to the login page.
this.$router.push({
name: 'mall',
params: {
id: 1,
name: 'Mall',
}
});
(2) Receive parameters in the mall page.
Mall page, ID: {{id}}, name: {{name}}
<script></p> <p>export default {</p> <p>props: ['id', 'name '],</p> <p>}</p> <p></script>
3. How to obtain login information on the mall page
In actual development, the mall page needs Only by obtaining the user's login information can you perform some operations, such as obtaining the user's shopping cart information, orders, etc. At this time, we can store the user information in the local cache when logging in, and then obtain the login information through the local cache on the mall page.
The specific implementation method is as follows:
(1) When the login is successful, the user information is stored in the local cache.
uni.setStorageSync('userInfo', JSON.stringify(userInfo));
(2) Obtain user information from the mall page.
Mall page, welcome: {{userInfo.name}}
<script></p> <p>export default {</p> <p>data() {</p> <p>return {</p> <p>userInfo: null,</p> <p>}</p> <p>},</p> <p>created() {</p> <p>this.getUserInfo();</p> <p>},</p> <p>methods: {</p> <p>getUserInfo() {</p> <p>let userInfo = uni.getStorageSync('userInfo');</p> <p>if (userInfo) {</p> <p>this.userInfo = JSON.parse(userInfo);</p> <p>}</p> <p>}</p> <p>}</p> <p>}</p> <p></script>
Through the above steps, we can realize the function of jumping from the uniAPP login page to the mall page, and at the same time solve the problem of how to receive parameters and obtain login information in the mall page. I hope this article can be helpful to uniAPP developers.
The above is the detailed content of How to jump to the mall from the uniAPP login page. For more information, please follow other related articles on the PHP Chinese website!