1. 程式人生 > >父頁面跳轉子頁面,子頁面返回父頁面並強制重新整理父頁面【記錄一下】

父頁面跳轉子頁面,子頁面返回父頁面並強制重新整理父頁面【記錄一下】

<input type="hidden" id="refreshed" value="no">(父頁面)

把下邊的程式碼加入js(父頁面呼叫)

if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) {
  window.onpageshow = function (event) {
    if (event.persisted) {
      window.location.reload()
    }
  };
} else {
  onload = function () {
    var refreshedId = document.getElementById("refreshed");
if (refreshedId.value === "no") {
  refreshedId.value = "yes";
} else {
  refreshedId.value = "no";
      location.reload();
    }
  }
}

子頁面 history.back(-1)返回父頁面,父頁面就會重新整理。

父頁面重新整理方法如果有資料操作的話(如vue)

var app = new Vue({
                el:'#box',
                data:{
                    arr:['aaa','bbb']

                }

});

可以在重新整理中寫function(){

            // app.arr[index] = val;//這種方法不重新整理頁面(不重新渲染,但資料確實有了)

             app.$set(app.arr,arr的index,要設定的arr[index]的值);

}