使用插件:svg-pan-zoom <template> <!-- svg圖--><div id="svgContainer"></div> </template><script> import svgPanZoom from 'svg-pan-zoom' import svgFile from '../datav/img/220kVscb.svg' // 路徑根據實際情況調整 export default {name: 'svgImage',data () {return {}},mounted () {this.$nextTick(() => {const svgContainer = document.getElementById('svgContainer')// 創建一個新的object元素來加載SVG文件const svgElement = document.createElement('object')const height = svgContainer.clientHeightsvgElement.type = 'image/svg+xml'svgElement.data = svgFilesvgElement.width = '100%'svgElement.height = height - 20// 將SVG元素添加到容器中svgContainer.appendChild(svgElement)// 等待SVG加載完成后再初始化svg-pan-zoom插件svgElement.onload = () => {const panZoom = svgPanZoom(svgElement, {zoomEnabled: true,controlIconsEnabled: true})// 當組件銷毀時,記得清理資源this.$once('hook:beforeDestroy', () => {panZoom.destroy()})}})} } </script><style lang="less"></style>