赞
踩
不考虑带宽的情况下,直接请求后端最大尺寸的照片。
记住公式:图片尺寸 = css尺寸 * DPR,只要公式成立,就一定是清晰的
- <template>
- <div>
- <img srcset="
- https://picsum.photos/id/88/150 1x,
- https://picsum.photos/id/88/300 2x,
- https://picsum.photos/id/88/600 4x,
- https://picsum.photos/id/88/900 6x,
- https://picsum.photos/id/88/1200 8x,
- " alt="">
- </div>
- </template>
-
- <script>
- export default{
- name: 'autoImg',
- data(){
- return {
-
- }
- }
- }
- </script>
- <style lang="less" scoped>
- img{
- width: 150px;
- height: 150px;
- }
- </style>
记住公式:图片尺寸 = css尺寸 * DPR,现在css尺寸不固定,DPR也不固定
- <template>
- <div>
- <img srcset="
- https://picsum.photos/id/88/150 150w,
- https://picsum.photos/id/88/300 300w,
- https://picsum.photos/id/88/600 600w,
- https://picsum.photos/id/88/900 900w,
- https://picsum.photos/id/88/1200 1200w,
- "
- sizes="
- (max-width: 300px) 150px, //当照片宽度最大是300px时,就当作是150px,然后乘以DPR(当为6时),自动选择900w的https://picsum.photos/id/88/900地址(150*6=900)
- (max-width: 600px) 300px,
- (max-width: 900px) 450px,
- (max-width: 1200px) 600px,
- 1200px
- "
- alt="">
- </div>
- </template>
-
- <script>
- export default {
- name: 'autoImg',
- data() {
- return {
-
- };
- }
- };
- </script>
- <style lang="less" scoped>
- img {
- width: 50vw;
- height: 50vh;
- display: block;
- margin: 0 auto;
- }
- </style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。