首页 > 其他 > 详细

vue实时获取页面的宽度,自适应屏幕

时间:2020-02-27 14:52:26      阅读:1195      评论:0      收藏:0      [点我收藏+]
data(){
        return{
            fullWidth:document.documentElement.clientWidth
        }
    },
    created(){
        window.addEventListener(‘resize‘, this.handleResize)
    },
    beforeDestroy: function () {
        window.removeEventListener(‘resize‘, this.handleResize)
    },
    computed:{
        ...mapGetters([
            ‘isCollapse‘,
        ]),
        rightWidth(){
            let leftWidth = this.isCollapse ? ‘64‘ : ‘200‘;
            console.log(this.fullWidth)
            return (this.fullWidth-leftWidth)+‘px‘
        }
    },
    methods: {
        handleResize (event) {
            this.fullWidth = document.documentElement.clientWidth
        },
    }  

 

vue实时获取页面的宽度,自适应屏幕

原文:https://www.cnblogs.com/ygunoil/p/12371802.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!