Technology Sharing

In vue, the picture is displayed in the div in proportion to its original size

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

The image is displayed in the div in proportion to its original size, which ensures that the image displayed on the web is the same shape as the actual image and retains the original image effect

The implementation code is as follows:

  1. <div style="padding: 0; width:400px;height:400px;position: absolute;border: 1px solid #eff2f6;">
  2. <img :src="imgOptions.img" style="width: 100%;height:100%;object-fit: contain;"/>
  3. </div>

The effect is as follows: