// refresh.vue
<template>
<div></div>
</template>
<script>
export default {
name: "refresh",
data() {
return {}
},
beforeRouteEnter(to, from, next) {
next(vm => {
vm.$router.replace({ path: from.path, query: to.query })
})
}
}
</script>
// router.vue
{
path: "/refresh",
name: "refresh",
component: () =>
import(/* webpackChunkName: "page" */ "@/components/refresh"),
meta: {
keepAlive: false,
isTab: false,
isAuth: false
}
}
// main.js (如果需要设置所有的)
router.beforeEach((to, from, next) => {
if (from.path === to.path) {
next({ path: "/refresh", query: to.query })
return
}
}
/**
* 复制文本
* @param text
*/
export function copyText(text) {
const input = document.createElement("input")
input.value = text
document.body.appendChild(input)
input.select()
document.execCommand("Copy")
window.setTimeout(function () {
document.body.removeChild(input)
}, 0)
}
/**
* esc监听全屏
*/
export const listenfullscreen = (callback) => {
function listen() {
callback()
}
document.addEventListener("fullscreenchange", function () {
listen()
})
document.addEventListener("mozfullscreenchange", function () {
listen()
})
document.addEventListener("webkitfullscreenchange", function () {
listen()
})
document.addEventListener("msfullscreenchange", function () {
listen()
})
}
/**
* 浏览器判断是否全屏
*/
export const fullscreenEnable = () => {
return document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen
}
/**
* 浏览器全屏
*/
export const re
let timer = setTimeout(()=> {})
this.$once("hook:beforeDestroy", () => {
clearTimeout(timer)
timer = null
})
<template>
<div class="countDown_container">
<slot v-bind="dateData"></slot>
</div>
</template>
<script>
import dayjs from "dayjs";
export default {
name: "countDown",
props: {
computeEndTimeFlag: Boolean, // 是否计算结束时间
nowTime: {
type: String | Number,
default: () => Date.now()
},
startTime: {
type: String | Number,
},
endTime: {
type: String | Number,
required: true,
},
showDay: Boolean,
},
data() {
return {
dateData: {},
realEndTime: null,
}
},
created() {
const realEndTime = this.computeEndTimeFlag ? new Date(this.endTime).getTime() : this.getRealEndTime()
this.realEndTime = realEndTime
this.$emit("getRealEndTime", realEndTime)
this.setDateData(realEndTime - new Date().getTime())
this.updateState();
// this.$options.data()//是原始data中的数据
// this.$data //是改变后的data中的数据
this.$root //表示app.vue中data的数据
Object.assign(this.$data, this.$options.data())
Number.prototype.toFixed = function (n) {
if (n != undefined && (isNaN(n) || Number(n) > 17 || Number(n) < 0)) {
throw new Error("输入正确的精度范围");
}
// 拆分小数点整数和小数
var num = this;
var f = '';
if (Number(num) < 0) {
num = -Number(num);
f = '-';
}
var numList = num.toString().split(".");
// 整数
var iN = numList[0];
// 小数
var dN = numList[1];
n = parseInt(n);
if (isNaN(n) || Number(n) === 0) {
// 0或者不填的时候,按0来处理
if(dN === undefined){
return num + '';
}
var idN = Number(dN.toString().substr(0, 1));
if (idN >= 5) {
if (Number(iN) < 0) {
iN = Number(iN) - 1
} else {
iN = Number(iN) + 1
}
}
return iN + '';
} else {
var dNL = dN === undefined ? 0 : dN.length;
if (dNL < n) {
// 如果小数位不够的话,那就补全
var oldN = num.toString().ind