为canvas画布动态设置背景图片
关键是将canvas和img标签放到同一个盒子里,盒子设置相对位置,并且canvas和img需要设置相同的相对位置
<div class="list3">
<canvas id="canvas" width="1276" height="800"></canvas>
<img :src=url id="scream" width="1276" height="800">
</div>
<style type="text/css">
#canvas{ position: absolute;z-index: 1; }
#scream{ position: absolute; }
.list3{ width: 1270px; height: 800px; float: right; border-style: solid; position:relative; }
</style>
<script type="text/javascript">
this.img_path = res.data['img_path'];
var c = document.getElementById( "canvas");
var ctx = c.getContext( "2d");
var img=document.getElementById("scream");
img.src = '/media/maps/' + this.img_path;
</script>