Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

dom - Displaying a profile picture that is being fetched from Github

I am a newbie and am attempting to display an image that is from my Github profile vs hardcoding it into the HTML. Currently, I have coded the following and the object is being displayed in my Javascript console.

const APIURL = 'https://api.github.com/users/'

getUser('JetimLee')


async function getUser(username) {
  try {
    const {
      data
    } = await axios(APIURL + username)

    console.log(data)
  } catch (err) {
    console.log(err)

 } 
}

My question is - how do I get the image from the profile to be displayed? Thank you so much in advance!

question from:https://stackoverflow.com/questions/65617722/displaying-a-profile-picture-that-is-being-fetched-from-github

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

enter image description here

You have an avatar_url field, set it's value as source of an image tag in your html.

Example:

const data = await axios('link');
const imgTag = document.getElementById('git-user-id');
imgTag.setAttribute('src', data.avatar_url);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...