Home > Web Front-end > Vue.js > How to return a page in vuejs

How to return a page in vuejs

藏色散人
Release: 2021-11-02 14:56:42
Original
3426 people have browsed it

Vuejs implements the method of returning to a page: 1. Through the "goOff(){this.$router.go(-1);}," method to click to return to the previous page; 2. Through "methods: {back(){if () {...}" method is used to return to the previous page. If there is no previous page, return to the home page.

How to return a page in vuejs

The operating environment of this article: windows7 system, vue2.9.6 version, DELL G3 computer.

How to return a page in vuejs?

vue implements clicking the button to return to the previous page:

1, how does vue click the button to return to the previous page?

This is the range of html code mounted by vue

      <div @click="goOff()">返回</div>
Copy after login

The following is the method of clicking to return

The first method only returns the previous page

           goOff(){
                this.$router.go(-1);
            },
Copy after login

The first The second way is to return to the previous page. If there is no previous page, return to the home page.

    methods: {
        back(){
            if (window.history.length <= 1) {
                this.$router.push({path:&#39;/&#39;})
                return false
            } else {
                this.$router.go(-1)
            }
        }
    },
Copy after login

2. Here is a little introduction to vue call interface knowledge.

           actAllProfit(){                //调取接口的函数
                var params = {};                //这是调取接口时的请求参数 明白点就是我们要传过去的参数
                var reqUrl = this.diviBaseUrl + &#39;/bonuses/grossProfit&#39;;               //这是后台接口地址
                this.$http.get(reqUrl,{               //get方式发送请求
                    params: params           //把外面声明的参数传过去
                }).then((res)=>{   //巧妙运用箭头函数
                    if(!res){return;}
                    this.allProfit = res.Profit; //res就是后台返回的所有数据 前端需要接收并保存
                })
            }
Copy after login

Recommended learning: "The latest 5 vue.js video tutorial selection

The above is the detailed content of How to return a page in vuejs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template