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’
然后注冊(cè)下:
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.intensediesel.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); }}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python如何寫個(gè)俄羅斯方塊2. 手把手教你用python發(fā)送短消息(基于阿里云平臺(tái))3. 測(cè)試模式 - XSL教程 - 54. Python結(jié)合百度語(yǔ)音識(shí)別實(shí)現(xiàn)實(shí)時(shí)翻譯軟件的實(shí)現(xiàn)5. 每日六道java新手入門面試題,通往自由的道路第二天6. python迭代器自定義類的具體方法7. 教你JS更簡(jiǎn)單的獲取表單中數(shù)據(jù)(formdata)8. python b站視頻下載的五種版本9. 《CSS3實(shí)戰(zhàn)》筆記--漸變?cè)O(shè)計(jì)(一)10. 讓chatgpt將html中的圖片轉(zhuǎn)為base64方法示例
