• 选择器获取
<template>
    <div>
        <canvas id='cvs' >
    </div>
</template>
<script>
    export default{
        mounted(){
            let canvas=document.querySelector('#cvs');
        }
    }
</script>

  • ref获取
<template>
    <div>
        <canvas ref='cvs' >
    </div>
</template>
<script>
    export default{
        mounted(){
            let canvas=this.$refs.cvs;
        }
    }
</script>

//vue中,在mounted之后的钩子 函数中才能进行dom操作,mounted完成dom挂载
Logo

前往低代码交流专区

更多推荐