组件 compontents/graphValidateCode/graphValidateCode.vue文件
<template>
<view :key="key"><canvas :style="{ width: width + 'px', height: height + 'px' }" canvas-id="imgcanvas" @click="refresh()" @error="canvasIdErrorCallback"></canvas></view>
</template>
<script>
export default {
data() {
return {
width: 90,
height: 40,
key:0
};
},
props: {
verCode:{
type:String,
default:''
}
},
watch: {
verCode: {
handler(newValue, oldValue) {
this.init();
},
deep: true
}
},
mounted(){
this.init();
},
methods: {
init:function(){
var context = uni.createCanvasContext('imgcanvas', this);
var w = this.width;
var h = this.height;
context.setFillStyle('#f2dccf');
context.setLineWidth(5);
context.fillRect(