<template>
    <div>
        <el-button @click="getCaptcha">get</el-button>
        {{ key }}
        <img :src="img" />
        <div>
            <el-input v-model="code"></el-input>
            <el-button @click="verify">verify</el-button>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            img: '',
            key: '',
            code: ''
        };
    },
    created() {
        this.getCaptcha();
    },
    methods: {
        getCaptcha() {
            this.$http.get('/captcha/get').then(res => {
                this.img = res.image;
                this.key = res.key;
            });
        },
        verify() {
            this.$http
                .get('/captcha/verify', {
                    key: this.key,
                    code: this.code
                })
                .then(res => {
                    this.$message.success(res);
                })
                .catch(e => {
                    this.$message.error(e.error);
                });
        }
    }
};
</script>
