Dynamic replacement pictures in Vue

Time:2021-10-14
<span @click="togle">
    <img :src=" this.i == 0 ? srcs : nosrc">
</span>

export default{
    data(){
        return{
            i:0,
            srcs:require('../images/[email protected]'),
            nosrc:require('../images/[email protected]')
        }
    },
    methods:{
        togle(){
            if(this.i==0){
               this.i=1;
            }else{
               this.i=0;
            }
        }
    }
}

Reprinthttp://www.51csdn.cn/article/180.html


vue

This work adoptsCC agreement, reprint must indicate the author and the link to this article