Home > Article > Web Front-end > How to return a page in vuejs
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.
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>
The following is the method of clicking to return
The first method only returns the previous page
goOff(){ this.$router.go(-1); },
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:'/'}) return false } else { this.$router.go(-1) } } },
2. Here is a little introduction to vue call interface knowledge.
actAllProfit(){ //调取接口的函数 var params = {}; //这是调取接口时的请求参数 明白点就是我们要传过去的参数 var reqUrl = this.diviBaseUrl + '/bonuses/grossProfit'; //这是后台接口地址 this.$http.get(reqUrl,{ //get方式发送请求 params: params //把外面声明的参数传过去 }).then((res)=>{ //巧妙运用箭头函数 if(!res){return;} this.allProfit = res.Profit; //res就是后台返回的所有数据 前端需要接收并保存 }) }
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!