vue 如何点击按钮返回上一页
1,vue 如何點擊按鈕返回上一頁呢?
???? 這是vue掛載的范圍html代碼
????? <div @click="goOff()">返回</div>
???? 下面是點擊返回的方法
????? 第一種只返回上一頁
?????????? goOff(){
?? ??? ??? ??? ?this.$router.go(-1);
?? ??? ??? ?},
????? 第二種 返回上一頁,如果沒有上一頁返回首頁
methods: {back(){if (window.history.length <= 1) {this.$router.push({path:'/'}) return false } else { this.$router.go(-1) } } },2,下面介紹一點vue調取接口小知識
?????????? 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就是后臺返回的所有數據 前端需要接收并保存
?? ??? ??? ???? })
?? ??? ???? }
***********************今天的文章就到這里了******************************
更多專業前端知識,請上 【猿2048】www.mk2048.com
總結
以上是生活随笔為你收集整理的vue 如何点击按钮返回上一页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: css随堂笔记(一)
- 下一篇: html5倒计时秒杀怎么做,vue 设