移動端Vue.js圖片預覽插件 | Mobile-friendly picture file preview Vue.js plugin with horizontal nav and bottom title.javascript
npm install --save vue-picture-preview
首先在項目的入口文件中引入, 調用 Vue.use 安裝。css
import vuePicturePreview from 'vue-picture-preview' Vue.use(vuePicturePreview)
在根組件添加 lg-preview 組件的位置vue
<!-- Vue root compoment template --> <div id="app"> <router-view></router-view> <lg-preview></lg-preview> </div>
對於全部圖片均可以使用 v-preview 指令來綁定他們的預覽功能java
<img v-for="(img,index) in imgs" v-preview="img.url" :src="img.url" :alt="img.title" :key="index" preview-title-enable="true" preview-nav-enable="true">
export default { data () { return { imgs: [ { url: 'http://covteam.u.qiniudn.com/ka2.jpg', title: 'pic1' }, { url: 'http://covteam.u.qiniudn.com/poster.png', title: 'pic2' } ] } } }
<style scoped> img { width: 100%; height: 100%; } </style>