首页 > 解决方案 > 当我尝试从 themoviedb API 获取图像时出现奇怪的字符

问题描述

我必须展示一些电影图片,themoviedb api但是当我尝试展示它们时,我只是有奇怪的角色

我试过用,atob()但这个功能不起作用。

export default {
  data() {
    return {
      info: null
    };
  },
  mounted() {
    axios
      .get(

"https://image.tmdb.org/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg? 
api_key=05b735a5f79822f887889281f45b295a"
      )
      .then(response => (this.info = response.data))
      .then(response => console.log(this.info));
  } 
};

console.log(this.info) return to me this :
�����JFIF�����������



)  )/'%'/9339GDG]]}



)  )/'%'/9339GDG]]}����"�����������������   �������� ����=��=��f��5�����@�����������&����Sv����u�
=thH�R]Z��ӫ|<L@����[�����4L�2�#�RT�uj�F�Ӈ���N�PB�����7���V�(��{;�
{3!Lt$M�SZSn�ͺ�٪�����=�����
Sͱ����PK��"hN�Р7�6�߷n���,�@���=˸:��������;;ez�Q��.co�1r��c��T^g��e�~Ū\Wՠ���M>����hGit�����P�����tt��A������cq��X���(���]�ѭ�/5\�����C*��bDu��}��5Z�������n��m��<�̵����LZ��1/�}��~5��Z�T�r��p��   P�Ϻ`��Pe��V���B�����G3���ϩ��a�/6>���
��>�j�  .]�
��s�@���2>ڛ������o��GY������*v����F+�z�

ETC ...

谁能告诉为什么会这样。?

编辑:

 url: null,
      http: "https://image.tmdb.org/t/p/w300/",
      key: "?api_key=05b735a5f79822f887889281f45b295a",
      image: null,
      name: ""
    };
  },
  mounted() {
    axios
       .get(
        "https://api.themoviedb.org/3/movie/popular? 
         api_key=05b735a5f79822f887889281f45b295a&language=en-US&page=1"
      )
      .then(response => (this.url = 
response.data.results[0].poster_path))
      .then(response => (this.image = this.http += this.url += 
this.key))

这东西行得通

标签: javascriptimageapi

解决方案


atob()用于解码base64,但您提供的资源是图像而不是base64编码的图像。

你可以用html来展示它

<img src="https://image.tmdb.org/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg?api_key=05b735a5f79822f887889281f45b295a" alt="Fight Club">

推荐阅读