導覽

v1.0.0
框架

Vue

在 Vue 呈現動態或固定的光學圖稿。

本頁內容

#動態圖示

Vue 是必要的 peer dependency。請在應用程式安裝 Vue 3.5 以上的 3.x 版本,並安裝 @master/icons-vue。

<script setup lang="ts">import { SearchIcon } from '@master/icons-vue';</script><template>  <SearchIcon :size="20" corner="rounded" label="Search" /></template>

動態入口會為每個匯入的圖示包含九種光學尺寸與圓角組合,以及各組合支援的線寬圖稿,與其他框架及 SVG 共用相同幾何。size 會選擇最接近的光學圖稿;corner 預設為 soft。

#固定圖示

<script setup lang="ts">import { SearchIcon } from '@master/icons-vue/16/soft';</script><template>  <button aria-label="Search"><SearchIcon /></button></template>

固定入口只包含一種光學尺寸與圓角。可將 16/soft 換成 16、20、24 與 sharp、soft、rounded 的任意組合。固定元件不接受 corner 或 opticalSize;size 只會縮放所選圖稿。

#框架行為

在 template 中使用 optical-size,例如 :optical-size="16"。SVG 屬性與事件監聽器會傳給 SVG 根元素。圖示為函式元件,元件 ref 並不是 SVG 元素 ref。

沒有標籤的圖示會視為裝飾。對有意義的圖示使用 label、aria-label 或 aria-labelledby,或替外層按鈕命名,詳見無障礙。

#自訂線寬

動態與固定入口都接受 strokeWidth,以原生單位與 0.25 為級距。它會選用重新繪製的幾何,而非修改 SVG 的線寬屬性。

<script setup lang="ts">import { SearchIcon } from '@master/icons-vue/24/soft';</script><template>  <SearchIcon :size="48" :stroke-width="2" /></template>

各光學尺寸支援的範圍與繪製方式,請見線寬。