Vize

vue/a11y-img-alt

要求图片提供 alt 属性,以支持无障碍访问。

默认严重程度 预设 自动修复 选项
warning 无 不支持 无

适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。

错误示例

静态图片和动态来源的图片都未提供 alt 属性。

<template>
<img src="/photo.jpg" />
<img :src="photo" />
</template>

正确示例

承载信息的图片使用描述性 alt 文本,装饰性图片使用空 alt,动态图片则绑定其描述。

<template>
<!-- Informative image -->
<img src="/photo.jpg" alt="Team photo from company retreat" />

<!-- Decorative image (empty alt) -->
<img src="/decoration.svg" alt="" />

<!-- Dynamic alt -->
<img :src="photo" :alt="photoDescription" />
</template>

配置(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/a11y-img-alt": "warn"
    }
  },
});

然后运行 vp run lint。

相关页面