ysfibm
ysfibm

Reputation: 436

SPFX webpart referencing images in html

I'm creating a simple SharePoint webpart using SPFX, I wanna reference images in the solution. I used this method:

require("@microsoft/loader-set-webpack-public-path!");

<img src="${require<string>('../../assets/logo.jpg')}" alt="My Company" />

But it doesn't work.

How to achieve that ?

Upvotes: 1

Views: 7031

Answers (1)

Lee
Lee

Reputation: 5493

Sample test demo:

No framework:

<img src="${require<string>('../../download.jpg')}" alt="My Company" />

enter image description here

React framework:

enter image description here

<img src={require('../../assets/panda.jpg')} alt="test" />

Upvotes: 8

Related Questions