vuejs 圖片預覽插件 v-viewer

https://github.com/mirari/v-viewer github地址。

1.安裝配置

npm install v-viewer --save

2.在main.js中引入

import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
 
//Vue.use(Viewer) 默認配置寫法
Vue.use(Viewer, {
    defaultOptions: {
        zIndex: 9999
    }
})

3.在頁面中使用

<template>
    <viewer :images="images">
       <img v-for="src in images" :src="src" :key="src" width="300">
    </viewer>
</template>
 
<script type="text/ecmascript-6">
    export default {
        name: "images",
        data() {
            return {
                images : []
            }
        },
        created() {
            //圖片是從後臺查的
            this.getData()
        },
        methods: {
            getData() {
                var _this = this
                _this.$http.get('/admin/attach/product')
                    .then(function (response) {
                        _this.images = response.data.data
                    })
                    .catch(function (err) {
                        console.log(err);
                    });
            }
        }
    }
</script>

images 數組格式

[
        "http://***************",
        "http://***************",
        "http://***************",
    ]

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章