AntV+Vue實現(xiàn)導出圖片功能
更新時間:2023年01月31日 11:09:31 作者:打小就霸
AntV?組織圖操作完畢以后,需要點擊按鈕將畫布以圖片的形式導出,這篇文章主要介紹了AntV結合Vue實現(xiàn)導出圖片功能,需要的朋友可以參考下
一、業(yè)務場景:
AntV 組織圖操作完畢以后,需要點擊按鈕將畫布以圖片的形式導出
二、問題描述:
官網(wǎng)上有4個方法,我用的是
graph.toFullDataURL(callback, type, imageConfig)
三、具體實現(xiàn)步驟:
(1)添加導出按鈕
<a-button type="primary" @click="exportImg">
導出圖譜
</a-button>(2)實現(xiàn)邏輯
exportImg(){
//這里涉及到了組件傳值,用的是子組件里面的方法
console.log(this.$refs.workflow.graph)
this.$refs.workflow.graph.toFullDataURL(// 第一個參數(shù)為 callback,必須
(res) => {
console.log(res); // 打印出結果
// 下載
var oA = document.createElement('a')
oA.download = this.tempObj.name
oA.href = res
document.body.appendChild(oA)
oA.click()
oA.remove() // 下載之后把創(chuàng)建的元素刪除
},
// 后兩個參數(shù)不是必須
'image/jpeg',
{
backgroundColor: '#fff',
padding: 10,
}
)
},四、完整代碼
<template>
<!--設置parentContent的寬高為瀏覽器大小-->
<div class="parentContent" ref="parentContent">
<a-button type="primary" @click="exportImg">
導出圖譜
</a-button>
<div id="container" ref="container"></div>
</div>
</template>
<script>
import G6 from '@antv/g6'
export default {
name: 'g6',
methods: {
exportImg(){
//這里涉及到了組件傳值,用的是子組件里面的方法
console.log(this.graph)
this.graph.toFullDataURL(// 第一個參數(shù)為 callback,必須
(res) => {
console.log(res); // 打印出結果
// 下載
var oA = document.createElement('a')
oA.download = '996'
oA.href = res
document.body.appendChild(oA)
oA.click()
oA.remove() // 下載之后把創(chuàng)建的元素刪除
},
// 后兩個參數(shù)不是必須
'image/jpeg',
{
backgroundColor: '#fff',
padding: 10,
}
)
},
}
</script>五、效果展示:

到此這篇關于AntV結合Vue實現(xiàn)導出圖片功能的文章就介紹到這了,更多相關Vue導出圖片內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue2項目導出操作實現(xiàn)方法(后端接口導出、前端直接做導出)
這篇文章主要給大家介紹了關于vue2項目導出操作實現(xiàn)方法的相關資料,文中介紹的是后端接口導出、前端直接做導出,通過代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-05-05

