美文网首页Vue.js前端开发笔记
axios 接受 base64 图片

axios 接受 base64 图片

作者: 一只肥豚鼠 | 来源:发表于2019-02-15 19:18 被阅读8次

首先设置img标签

          <img v-bind:src="captchaBase64Img" @click="SetBase64Img" height="60px" width="240px"/>

data()函数设置

data() {
    return {
      captchaBase64Img: ""
    };
  },

methods函数

  methods: {
    // 设置验证码图片
    SetBase64Img: function() {
      let captchaBase64Url = this.GetServerUrl() + "/captcha";
      this.axios
        .get(captchaBase64Url)
        .then(response => {
          this.captchaBase64Img = response.data;
        })
        .catch(error => {
          alert(error);
        });
    }
  }

注意:在写axios部分时一定要按照上面部分写,如果写成下面的方式,肯定会翻车

this.axios
        .get(captchaBase64Url)
        .then(function (response)  {
          this.captchaBase64Img = response.data;
        })
        .catch(function(error){
          alert(error);
        });

mounted函数

mounted() {
    this.SetBase64Img();
  },

相关文章

网友评论

    本文标题:axios 接受 base64 图片

    本文链接:https://www.haomeiwen.com/subject/arwmeqtx.html