it图片过滤灰色兼容


<template>
    <div :style="`width:${width}px;height:${height}px`">
      <img :src="imgSrc" v-if="!isGray||!isIE11">
      <div v-else>
        <svg overflow="hidden" preserveAspectRatio="none slice" :width="width" :height="height">
         <image overflow="visible" preserveAspectRatio="none slice" x='0' y='0' :width="width" :height="height" :xlink:href="imgSrc" filter="url(#grayscle)"></image>

        </svg>
      </div>
    </div>
</template>

<script>
    export default {
        name:"grayImg",
        props:{
            imgSrc:{
                type:String,
                default:""
            },
            width:{
                type:[Number,String],
                default:150
            },
            height:{
                type:[Number,String],
                default:90
            }
        },
        computed: {
            isGray() {
                return window.sessionStorage.getItem('skin')=='default';
            },
            isIE11(){
                return navigator.userAgent.indexOf('Trident')!==-1;
            }
        },
        
    }
</script>

<style lang="scss" scoped>
img{
    height:100%;
    width:100%;
}
</style>



// <template>
//    <svg xmlns=" http://www.w3.org/2000/svg" style="display:none">
//      <filter  id="grayscale">
//        <feColorMatrix type="matrix"values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"/>
//      </filter>
//    </svg>
// </template>

// <script>
//     export default {
//         name:"grayscale"
//     }
// </script>


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容