在vue中使用screenfull?依賴,實現(xiàn)全屏組件方式
vue使用screenfull依賴,實現(xiàn)全屏組件
需求:將頁面全屏化,實現(xiàn)按F11全屏的效果
實現(xiàn):
1.下載screenfull依賴
npm install --save screenfull
2.在components文件夾下封裝一個全屏組件FullScreen
index.vue代碼如下,直接cv就可以使用
<template> <div class="full-screen-wrapper" @click="handleFullscreen"> <el-tooltip effect="dark" :content="isFullscreen ? '退出全屏' : '全屏'" placement="bottom" > <i :class="[ 'icon', !isFullscreen ? 'vue-dsn-icon-fullscreen' : 'vue-dsn-icon-tuichuquanping', ]" /> </el-tooltip> </div> </template> <script> import screenfull from "screenfull"; export default { name: "FullScreen", data() { return { isFullscreen: false, }; }, mounted() { this.init(); }, beforeDestroy() { this.destroy(); }, methods: { handleFullscreen() { if (screenfull.enabled) { this.$message({ message: "不支持全屏!", type: "warning", }); return false; } screenfull.toggle(); }, change() { this.isFullscreen = screenfull.isFullscreen; }, init() { if (!screenfull.enabled) { screenfull.on("change", this.change); } }, destroy() { if (!screenfull.enabled) { screenfull.off("change", this.change); } }, }, }; </script> <style lang="less"> .full-screen-wrapper { float: left; width: 22px; height: 22px; padding: 4px; cursor: pointer; .icon { font-size: 24px; } &:hover { color: #409eff; } } </style>
在哪里需要調(diào)用這個組件,就可以通過組件調(diào)用的方式來直接調(diào)用
vue使用Screenfull全屏切換
1.在終端執(zhí)行命令 npm install --save screenfull
2.在components文件中創(chuàng)建Screenfull文件里面的代碼如下
<template> <div> <svg-icon :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="click" /> </div> </template> <script> import screenfull from 'screenfull' export default { name: 'Screenfull', data() { return { isFullscreen: false } }, mounted() { this.init() }, beforeDestroy() { this.destroy() }, methods: { click() { if (!screenfull.enabled) { this.$message({ message: 'you browser can not work', type: 'warning' }) return false } screenfull.toggle() }, change() { this.isFullscreen = screenfull.isFullscreen }, init() { if (screenfull.enabled) { screenfull.on('change', this.change) } }, destroy() { if (screenfull.enabled) { screenfull.off('change', this.change) } } } } </script> <style scoped> .screenfull-svg { display: inline-block; cursor: pointer; fill: #5a5e66;; width: 20px; height: 20px; vertical-align: 10px; } </style>
3.在需要的用的頁面引入我們的Screenfull文件
4.頁面的使用方法
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue-resource 攔截器interceptors使用詳解
這篇文章主要介紹了vue-resource 攔截器interceptors使用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01解決ant-design-vue中menu菜單無法默認(rèn)展開的問題
這篇文章主要介紹了解決ant-design-vue中menu菜單無法默認(rèn)展開的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10解決vue單頁面應(yīng)用中動態(tài)修改title問題
這篇文章主要介紹了解決vue單頁面應(yīng)用中動態(tài)修改title問題,本文通過示例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06在vue中使用export?default導(dǎo)出的class類方式
這篇文章主要介紹了在vue中使用export?default導(dǎo)出的class類方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03