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就是後臺返回的所有數據 前端需要接收並保存
})
}