You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Pug中实现动态v-slot名称的循环渲染?

可以实现,正确写法如下

你需要用动态插槽名的语法,在Pug里通过方括号包裹表达式来实现动态的v-slot属性:

template(v-for="(tab, index) of tabs" v-slot:[`item-title.${index + 1}`])
  .tab
    ThemeIcon(:themeId=tab.themeId)
    div {{ tab.content }}

补充说明:

  • 原代码里的插槽序号从1开始,所以循环中要通过index + 1来对应序号
  • 你的tabs数据结构需要匹配如下格式:
data() {
  return {
    tabs: [
      { themeId: 'welcome', content: 'Welcome' },
      { themeId: 'themes', content: 'Themes' },
      { themeId: 'timeline', content: 'Timeline' }
    ]
  }
}
  • 模板中的文本要使用插值语法{{ tab.content }},否则会直接渲染成字符串"tab.content"

内容的提问来源于stack exchange,提问作者Steve Bennett

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 01:10:28