html - vue组件和tabindex,你是怎么做的?
问题描述
我有一个自定义视图组件,它呈现为三个选择列表,“年”、“制造”和“模型”,它对我来说效果很好。
我的问题在于它动态放置在父表单上时......标签顺序不正常,我的研究似乎表明没有设置 tabindex 是正常的。
假设我有这样的事情:
<input type="text" v-model="name" tabindex="1">
<my-widget v-if="someCondition"> </my-widget>
<input type="text" v-model="shop" tabindex="5">
如何告诉 myWidget 将我的小部件内的选择的 tabindex 设置为 2、3、4?理想情况下,我希望能够在同一页面上使用其中两个小部件,这样硬编码就不起作用了。
有人对在组件内分配 tabindex 的最佳方法有任何想法吗?
解决方案
您可以将 tabindex 作为 my-widget 组件上的道具,以便它可以是动态的。例如
我的小部件组件
<template>
<div>
<input type="text" :tabindex="tabindex"/>
<input type="text" :tabindex="tabindex + 1"/>
</div>
</template>
<script>
export default {
props: {
tabindex: {
type: Number,
required: false,
default: 1
}
}
</script>
所以你的代码看起来像
<input type="text" v-model="name" tabindex="1">
<my-widget v-if="someCondition"
:tabindex="2"
> </my-widget>
<input type="text" v-model="shop" tabindex="5">
如果你添加另一个
<my-widget v-if="someCondition"
:tabindex="6"
> </my-widget>
推荐阅读
- tags - 如何通过 vsphere rest api 配置 vm 标签
- javascript - 渲染错误:“TypeError:无法读取未定义的属性 '0'”v-for 循环
- azure - 在 Azure Maps 中显示矢量切片 (PBF)
- oop - 为什么 Haskell 不需要工厂模式?以及在 Haskell 中,OOP 中的模式解决的需求是如何解决的?
- php - SSH 隧道 - MySQL 服务器已消失
- ios - 带有图像的单元格的 UICollectionView 初始滚动滞后
- c# - Microsoft Graph SDK:按 Guid 过滤会产生语法错误
- html - 如何将用户输入的值从我的前端 HTML 发送到我的后端服务器?
- html - Chrome 在生产中不显示 WEBP 图像
- r - 使用 ggraph::geom_edge_link() 绘制因子水平的行为