优化代码

This commit is contained in:
不做码农 2022-02-23 21:17:46 +08:00
parent 31cee32404
commit ae31b3ec69

View File

@ -5,54 +5,54 @@
</template> </template>
<script> <script>
import screenfull from 'screenfull' import screenfull from "screenfull";
export default { export default {
name: 'Screenfull', name: "Screenfull",
data() { data() {
return { return {
isFullscreen: false isFullscreen: false,
} };
}, },
mounted() { mounted() {
this.init() this.init();
}, },
beforeDestroy() { beforeDestroy() {
this.destroy() this.destroy();
}, },
methods: { methods: {
click() { click() {
if (!screenfull.enabled) { if (!screenfull.enabled) {
this.$message({ this.$message({
message: 'you browser can not work', message: "you browser can not work",
type: 'warning' type: "warning",
}) });
return false return false;
} }
screenfull.toggle() screenfull.toggle();
}, },
change() { change() {
this.isFullscreen = screenfull.isFullscreen this.isFullscreen = screenfull.isFullscreen;
}, },
init() { init() {
if (screenfull.enabled) { if (screenfull.enabled) {
screenfull.on('change', this.change) screenfull.on("change", this.change);
} }
}, },
destroy() { destroy() {
if (screenfull.enabled) { if (screenfull.enabled) {
screenfull.off('change', this.change) screenfull.off("change", this.change);
} }
} },
} },
} };
</script> </script>
<style scoped> <style scoped>
.screenfull-svg { .screenfull-svg {
display: inline-block; display: inline-block;
cursor: pointer; cursor: pointer;
fill: #5a5e66;; fill: #5a5e66;
width: 20px; width: 20px;
height: 20px; height: 20px;
vertical-align: 10px; vertical-align: 10px;