• vuex搭配screenfull实现全屏


    安装

    npm install --save screenfull

    简单使用

    <template>
      <span @click='clickFullscreen'>全屏</span>
    </template>
     
    <script>
      import screenfull from 'screenfull'
      export default{
        name: 'screenfull',
        data(){
          return {
            isFullscreen: false
          }
        },
        methods:{
          clickFullscreen(){
            if (!screenfull.isEnabled) {
              this.$message({
                message: 'you browser can not work',
                type: 'warning'
              })
              return false
            }
            screenfull.toggle()
          }
        }
      }
    </script>

    搭配vuex使用

    import screenfull from 'screenfull'
    export default {
        namespaced: true,
        state: {
            // 全屏激活
            active: false
        },
        actions: {
            /**
             * @description 初始化监听
             */
            listen({ commit }) {
                return new Promise(resolve => {
                    if (screenfull.enabled) {
                        screenfull.on('change', () => {
                            console.log('1')
                            if (!screenfull.isFullscreen) {
                                commit('set', false)
                            }
                        })
                    }
                    // end
                    resolve()
                })
            },
            /**
             * @description 切换全屏
             */
            toggle({ commit }) {
                return new Promise(resolve => {
                    if (screenfull.isFullscreen) {
                        screenfull.exit()
                        commit('set', false)
                    } else {
                        screenfull.request()
                        commit('set', true)
                    }
                    // end
                    resolve()
                })
            }
        },
        mutations: {
            /**
             * @description 设置 store 里的全屏状态
             * @param {Object} state vuex state
             * @param {Boolean} active active
             */
            set(state, active) {
                state.active = active
            }
        },
        getters: {
        }
    }
  • 相关阅读:
    POJ2299--树状数组求逆序数
    每周总结
    2016湖南省赛--A题--2016
    ACM暑期训练总结
    jQuery实现拖动布局并将排序结果保存到数据库
    TP3.2整合kindeditor
    TP3.2整合uplodify文件上传
    Sublime Text3 使用
    ThinkPHP AJAX分页及JS缓存的应用
    Thinkphp分页类使用
  • 原文地址:https://www.cnblogs.com/theblogs/p/13099619.html
Copyright © 2020-2023  润新知