加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Vant Image 图片

发布时间:2023-04-20 11:23:28 所属栏目:教程 来源:
导读:增强版的 img 标签,提供多种图片填充模式,支持图片懒加载、加载中提示、加载失败提示

import Vue from 'vue';import { Image } from 'vant';

Vue.use(Image);
基础用法与原生img标签一致,
增强版的 img 标签,提供多种图片填充模式,支持图片懒加载、加载中提示、加载失败提示

import Vue from 'vue';import { Image } from 'vant';
 
Vue.use(Image);
基础用法与原生img标签一致,可以设置src、width、height、alt等原生属性

<van-image
  width="100"
  height="100"
  src="https://img.yzcdn.cn/vant/cat.jpeg" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" 
/>
填充模式
通过fit属性可以设置图片填充模式,可选值见下方表格

<van-image
  width="10rem"
  height="10rem"
  fit="contain"
  src="https://img.yzcdn.cn/vant/cat.jpeg" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" 
/>
圆形图片
通过round属性可以设置图片变圆,注意当图片宽高不相等且fit为contain或scale-down时,将无法填充一个完整的圆形。

<van-image
  round
  width="10rem"
  height="10rem"
  src="https://img.yzcdn.cn/vant/cat.jpeg" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"
/>
图片懒加载
设置lazy-load属性来开启图片懒加载,需要搭配 Lazyload 组件使用

<van-image
  width="100"
  height="100"
  lazy-load
  src="https://img.yzcdn.cn/vant/cat.jpeg" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" 
/>
import Vue from 'vue';import { Lazyload } from 'vant';
 
Vue.use(Lazyload);
加载中提示
Image组件提供了默认的加载中提示,支持通过loading插槽自定义内容

<van-image src="https://img.yzcdn.cn/vant/cat.jpeg" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
  <template v-slot:loading>
    <van-loading type="spinner" size="20" />
  </template>
</van-image>

 

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章