---
title: "Ext.Img"
description: "xtype 为 image 的 Ext JS 原生组件参考。"
---

> Documentation Index
> Fetch the complete documentation index at: https://ag.879818327.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Ext.Img

源码定义：`ext-all-debug.js:41511`。分类：基础组件与提示。

## 创建示例

```javascript
var component = Ext.create("Ext.Img", {
  xtype: "image",
  alt: '',
  ariaRole: 'img',
  autoEl: 'img',
  baseCls: Ext.baseCSSPrefix + 'img',
  renderTo: Ext.getBody()
});
```

## 属性

| 属性 | 类型 | 默认值 | 说明 | 配置示例 |
| --- | --- | --- | --- | --- |
| `alt` | `String` | `''` | 配置组件的 `alt` 选项。 | `alt: ''` |
| `ariaRole` | `String` | `'img'` | 组件在辅助技术中的 ARIA 角色。 | `ariaRole: 'img'` |
| `autoEl` | `String` | `'img'` | 配置组件的 `autoEl` 选项。 | `autoEl: 'img'` |
| `baseCls` | `Mixed` | `Ext.baseCSSPrefix + 'img'` | 配置 `baseCls` 对应的 CSS 类名。 | `baseCls: Ext.baseCSSPrefix + 'img'` |
| `imgCls` | `String` | `''` | 配置 `imgCls` 对应的 CSS 类名。 | `imgCls: ''` |
| `maskOnDisable` | `Boolean` | `false` | 控制是否启用 `maskOnDisable` 行为。 | `maskOnDisable: false` |
| `src` | `String` | `''` | 配置组件的 `src` 选项。 | `src: ''` |
| `stretch` | `Boolean` | `true` | 控制是否启用 `stretch` 行为。 | `stretch: true` |
| `title` | `String` | `''` | 面板或窗口显示的标题。 | `title: ''` |

## 方法

| 方法 | 参数 | 说明 | 调用示例 |
| --- | --- | --- | --- |
| `initComponent` | `` | 初始化组件及其子项。 执行时会保留父类默认行为、更新 `autoEl` 状态。源码涉及 `callParent()`。 | `component.initComponent()` |
| `getElConfig` | `` | 读取并返回 `elConfig`。 执行时会保留父类默认行为。源码涉及 `callParent()`。 | `component.getElConfig()` |
| `onAdded` | `` | 处理 `added` 回调。 执行时会保留父类默认行为、更新 `oldSrc`、`bindFileField` 状态。源码涉及 `callParent()`、`setSrc()`。 | `component.onAdded()` |
| `removeFile` | `` | 移除 `file`。源码涉及 `setSrc()`。 | `component.removeFile()` |
| `openFile` | `` | 处理 `openFile` 操作。 | `component.openFile()` |
| `onRender` | `` | 生成 `on` 的渲染结果。 执行时会保留父类默认行为、派发 `click` 事件、更新 `imgEl` 状态。源码涉及 `callParent()`、`mon()`、`fireEvent()`。 | `component.onRender()` |
| `onDestroy` | `` | 处理 `destroy` 回调。 执行时会保留父类默认行为、更新 `imgEl` 状态。源码涉及 `callParent()`。 | `component.onDestroy()` |
| `setStretch` | `stretch` | 设置 `stretch`。 执行时会更新 `stretch` 状态。源码涉及 `setSrc()`。 | `component.setStretch(...)` |
| `setSrc` | `src` | 设置 `src`。 执行时会更新 `src` 状态。 | `component.setSrc(...)` |
| `setGlyph` | `glyph` | 设置 `glyph`。 | `component.setGlyph(...)` |

## 事件

源码中未找到该组件自身注册的事件；可监听继承事件。

Source: https://ag.879818327.xyz/ext/basic/img/index.mdx
