![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/df6915b1d3f0d810530b5ed8605fb8a6.png)
1.
<span
@click="randyzm()"
style="display: inline-block;text-align: center; width: 90px;font-size: 20px; height: 32px; line-height:32px; color: #2b3b4b;background-color: #1ea7fe"
>{
{code}}</span>
data(){
return{
code:''
}
}
randyzm() {
let code = ''
let coden = ''
var codeLength = 4
var random = new Array(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z'
)
for (var i = 0; i < codeLength; i++) {
var index = Math.floor(Math.random() * 62)
code += random[index]
coden += random[index]
}
this.code = coden
console.log(this.code)
},
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9ec631eada21ae9456467a970cf51582.png)
2. 封装组建
父组建
<template>
<div class="home">
<vue-image @getIdentifyCode="getIdentifyCodes" />
</div>
</template>
<script>
import VueImage from '../../components/echarts/vueImageVerify.vue'
components:{
VueImage
},
methods:{
getIdentifyCodes(value) {
console.log('------', value)
}
}
</script>
子组建
<template>
<div class="div" @click="createdCode">
<canvas id="div" :width="contentWidth" :height="contentHeight"></canvas>
</div>
</template>
<script>
import Vue from 'vue'
export default Vue.extend({
props: {
fontSizeMin: {
type: Number,
default: 25
},
fontSizeMax: {
type: Number,
default: 30
},
backgroundColorMin: {
type: Number,
default: 255
},
backgroundColorMax: {
type: Number,
default: 255
},
colorMin: {
type: Number,
default: 0
},
colorMax: {
type: Number,
default: 160
},
lineColorMin: {
type: Number,
default: 100
},
lineColorMax: {
type: Number,
default: 255
},
dotColorMin: {
type: Number,
default: 0
},
dotColorMax: {
type: Number,
default: 255
},
contentWidth: {
type: Number,
default: 120
},
contentHeight: {
type:</