feat(): 改为vite
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export { default } from "./plugins/visibility";
|
||||
export { default as VisibilityPlugin } from "./plugins/visibility";
|
||||
@@ -0,0 +1,46 @@
|
||||
function install(Vue) {
|
||||
Vue.mixin({
|
||||
created() {
|
||||
const onShowHook = this.$options.onShow;
|
||||
const onHideHook = this.$options.onHide;
|
||||
|
||||
if (onShowHook != null || onHideHook != null) {
|
||||
this.visibilitychangeCallback();
|
||||
document.addEventListener(
|
||||
"visibilitychange",
|
||||
this.visibilitychangeCallback
|
||||
);
|
||||
}
|
||||
},
|
||||
destroyed() {
|
||||
document.removeEventListener(
|
||||
"visibilitychange",
|
||||
this.visibilitychangeCallback
|
||||
);
|
||||
},
|
||||
methods: {
|
||||
visibilitychangeCallback() {
|
||||
const onShowHook = this.$options.onShow?.bind(this);
|
||||
const onHideHook = this.$options.onHide?.bind(this);
|
||||
|
||||
if (document.visibilityState == "visible") {
|
||||
console.log("visible");
|
||||
if (typeof onShowHook === "function") {
|
||||
onShowHook();
|
||||
}
|
||||
}
|
||||
|
||||
if (document.visibilityState == "hidden") {
|
||||
console.log("hidden");
|
||||
if (typeof onHideHook === "function") {
|
||||
onHideHook();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
install,
|
||||
};
|
||||
Reference in New Issue
Block a user