Big preview of background management system

1. Requirements:

Click the cover image in the list to preview it, and click it again to close

2. Effect:

3. Steps:

(1) Bind the click event and pass the id of the picture into it

<el-table-column  label="课程封面" width="150" >
    <template  slot-scope="scope" >
       <img :src="scope.row.cover" alt="" 
         @click="previewPic(scope.row.cover)">
    </template>
</el-table-column>

(2) Set the bullet box to display the picture, and the bullet box is initialized to the closed state,

         Use a new variable to receive the picture, and bind the "click to close the picture" event at the same time

<el-dialog :visible.sync="dialogVisible" 
        :modal="false"  :show-close="false" >
     <div style="text-align: center;">
        <img :src="previewpic" alt=""  @click="close()" >
     </div>
</el-dialog>


data() {
    return {
        previewpic:"",
        dialogVisible:false
    }
}

(3) Write the events of previewing pictures and closing pictures in methods

//预览大图
previewPic(url) {
   this.previewpic = url; //将接收的图片赋值给弹框里面的图片
   this.dialogVisible = true;
 },
//点击图片关闭预览
close() {
   this.dialogVisible = false;
},

Guess you like

Origin blog.csdn.net/ZHENGCHUNJUN/article/details/126570885