Vue基于iview table展示圖片實(shí)現(xiàn)點(diǎn)擊放大
首先先安裝依賴:
npm install v-viewer --save
然后全局引入,我這邊是在main.js里面操作寫的:
import Viewer from ’v-viewer’import ’viewerjs/dist/viewer.css’
然后注冊下:
Vue.use(Viewer)Viewer.setDefaults({ Options: { ’inline’: true, ’button’: true, ’navbar’: true, ’title’: true, ’toolbar’: true, ’tooltip’: true, ’movable’: true, ’zoomable’: true, ’rotatable’: true, ’scalable’: true, ’transition’: true, ’fullscreen’: true, ’keyboard’: true, ’url’: ’data-source’ }})
使用的一個(gè)demo就是:
<viewer :images='tupians'> <i-col span='4' v-for='item in tupians'> <div class='detailed'> <img :src='http://www.piao2010.com/bcjs/item.img' alt=''> </div> </i-col></viewer>
其中item.img其實(shí)就是一個(gè)路徑。
在回到iview表格中,
需要以
h(’xxxx’, {props: { trigger: ’hover’, placement: ’top’, content: ’二維碼’} }, [ ])
這種格式渲染出來,第一個(gè)參數(shù)是標(biāo)簽,第二參數(shù)是標(biāo)簽里面可以含props(vue的v-bind),也可以包含屬性。第三個(gè)參數(shù)是數(shù)組,表示子標(biāo)簽。子標(biāo)簽也是這種格式的,以此遞歸下去。
所以改寫成這種格式的,在本人項(xiàng)目中的一個(gè)demo如下,就可以實(shí)現(xiàn)在表格中點(diǎn)擊圖片進(jìn)行放大展示:
{ title: ’二維碼’, align: ’center’, render: (h, params) => { console.log(’h, param’, params); let devicesArr = []; let photo = []; photo.push(’/erweima/’+params.row.pt_number+’.png’); devicesArr.push( h(’Tooltip’, {props: { trigger: ’hover’, placement: ’top’, content: ’二維碼’} }, [h(’viewer’, { props:{ images:photo }}, [ h(’img’, { attrs: { src:photo[0], style: ’width: 22px;margin-right:5px’ }, })]) ]) ); return h(’div’, devicesArr); }}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Android 7.0 運(yùn)行時(shí)權(quán)限彈窗問題的解決2. java實(shí)現(xiàn)圖形化界面計(jì)算器3. IDEA的Mybatis Generator駝峰配置問題4. IIS Express 取代 ASP.NET Development Server的配置方法5. Spring-Richclient 0.1.0 發(fā)布6. 解決idea中yml文件不識(shí)別的問題7. IntelliJ Idea2017如何修改緩存文件的路徑8. IntelliJ IDEA設(shè)置條件斷點(diǎn)的方法步驟9. javascript設(shè)計(jì)模式 ? 建造者模式原理與應(yīng)用實(shí)例分析10. Python使用oslo.vmware管理ESXI虛擬機(jī)的示例參考
