1.首先在main.js 里定义cookie的get set 方法
Vue.prototype.getUrlParam = function (name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
let r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
Vue.prototype.getCookie = function (key) {
var arr, reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return arr[2];
else
return null;
}
2.老版本去往新版本
//设置cookie值为新版本
this.setCookie("version", "new");
/*老版本跳转到新版本*/
location.href = " URL "
3.新版本调往老版本 反之
//设置cookie值为老版本
this.setCookie("version", "old");
/*老版本跳转到新版本*/
location.href = " URL "
4.用户退出小程序后,重新进入时,判断版本
在vue初始化的时候 去获取cookie ,根据cookie的不同去往不同的版本
vue mounted 每次进入页面前 自动触发
mounted() {
//获取 cookie 的值
let cookieValue = this.getCookie("version");
if (cookieValue === "new") {
location.href = '新版本路径'
}else{
location.href = '老版本路径'
}
}