vue computed 实现七牛云缩略图处理

学习 · 2021-04-27
computed: {
        loadSrc(){
            let that = this;
            const { width, height, thumb, imageSrc} = that;
            // 基础路径
            let loadSrc = imageSrc + (imageSrc.indexOf('?') !== -1  ? '|' : '?')
            // 缩略图处理
            if(thumb == true || typeof thumb == 'object'){
                 // 设定有宽高的
                if( typeof thumb == 'object'){
                    const [width, height] = thumb;
                    loadSrc += 'imageView2/3/w/' + parseInt(width) + '/h/' + parseInt(height) + '/q/100';
                }else // 没有设定走当前wh
                    loadSrc += `imageView2/3/w/${parseInt(width)}/h/${parseInt(height)}/q/100`;
            }
            // 无缩略返回
            return loadSrc;
        }
    }
Theme Jasmine by Kent Liao | 桂ICP备15008025号-6