created() {
if (this.getCookie('dataPasswordAdmin')) {
// 存在
} else {
// 不存在
}
},
methods: {
//提交按钮
checkDataPassword() {
this.dataPassword = 123
// 密码存储日期 15天
this.setCookie('dataPasswordAdmin', this.dataPassword, 'd15')
},
// 存储cookie
setCookie(name, value, time) {
var strsec = this.getsec(time)
var exp = new Date()
exp.setTime(exp.getTime() + strsec * 1)
document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString()
},
//转换时间
getsec(str) {
var str1 = str.substring(1, str.length) * 1
var str2 = str.substring(0, 1)
if (str2 === 's') {
return str1 * 1000
} else if (str2 === 'h') {
return str1 * 60 * 60 * 1000
} else if (str2 === 'd') {
return str1 * 24 * 60 * 60 * 1000
}
},
// 判断cookie存储的数据是否存在
getCookie(name) {
var arr = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
if (document.cookie.match(reg)) {
arr = document.cookie.match(reg)
return unescape(arr[2])
} else {
return null
}
},
}
网友评论