vue-cli點(diǎn)擊實(shí)現(xiàn)全屏功能
本文實(shí)例為大家分享了vue-cli點(diǎn)擊實(shí)現(xiàn)全屏功能的具體代碼,供大家參考,具體內(nèi)容如下
項(xiàng)目中有點(diǎn)擊按鈕實(shí)現(xiàn)全屏功能
方式一:js實(shí)現(xiàn)全屏
代碼如下:
<template> <div> <a-button type='primary' @click='screen'>全屏</a-button> </div></template><script> export default { name: 'index', data(){ return{ fullscreen: false } }, methods:{ screen(){ let element = document.documentElement; if (this.fullscreen) { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } } else { if (element.requestFullscreen) { element.requestFullscreen(); } else if (element.webkitRequestFullScreen) { element.webkitRequestFullScreen(); } else if (element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if (element.msRequestFullscreen) { // IE11 element.msRequestFullscreen(); } } this.fullscreen = !this.fullscreen; } } }</script><style scoped></style>
方式二:使用的是sreenfull插件,執(zhí)行命令安裝
npm install --save screenfull
在使用的頁面正確引入:
import screenfull from ‘screenfull’
代碼如下:
<template> <div> <a-button type='primary' @click='screen'>全屏</a-button> </div></template><script> import screenfull from ’screenfull’ export default { name: 'home', data() { return { //默認(rèn)不全屏 isFullscreen: false } }, methods: { screen(){ // 如果不允許進(jìn)入全屏,發(fā)出不允許提示 if (!screenfull.enabled) { this.$message(’您的瀏覽器不能全屏’); return false } screenfull.toggle(); this.$message.success(’全屏啦’) } } }</script><style scoped></style>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 在Vue中創(chuàng)建可重用的 Transition的方法2. Vue判斷數(shù)組內(nèi)是否存在某一項(xiàng)的兩種方法3. JS實(shí)現(xiàn)簡單貪吃蛇小游戲4. Python CSS選擇器爬取京東網(wǎng)商品信息過程解析5. JSP語法詳解6. python 利用 PIL 將數(shù)組值轉(zhuǎn)成圖片的實(shí)現(xiàn)7. .Net6.0+Vue3實(shí)現(xiàn)數(shù)據(jù)簡易導(dǎo)入功能全過程8. PHP中for循環(huán)語句的幾種“變態(tài)”用法9. Java 獲取 jar包以外的資源操作10. PHP百行代碼快速構(gòu)建簡易聊天室
