【Vue 全家桶】4、Vue中的ajax(http请求方法)

目录

slot插槽

默认插槽

具名插槽

作用域插槽

html 复制代码
<!-- 子组件 template -->
<div>
  <header>
    <slot name="header"></slot> <!-- 具名插槽 -->
  </header>
  <main>
    <slot></slot> <!-- 默认插槽 -->
  </main>
  <footer>
    <slot name="footer"></slot> <!-- 具名插槽 -->
  </footer>
</div>

<!-- 父组件使用 -->
<my-component>
  <template v-slot:header>
    这里是头部内容
  </template>
  <template v-slot:default> <!-- 或者省略 :default -->
    这里是主体内容
  </template>
  <template #footer> <!-- # 是 v-slot: 的简写 -->
    这里是底部内容
  </template>
</my-component>


<!-- 子组件 template -->
<div>
  <ul>
    <li v-for="item in items" :key="item.id">
      <slot :item="item"></slot> <!-- 作用域插槽 -->
    </li>
  </ul>
</div>

<!-- 父组件使用 -->
<my-component :items="itemsList">
  <template v-slot:default="{ item }"> <!-- 解构获取 item -->
    {{ item.name }} - ${{ item.price }}
  </template>
</my-component>
相关推荐
晓得迷路了3 分钟前
栗子前端技术周刊第 141 期 - Next.js 16.3、npm 安全事件、2026 CSS 现状调查报告结果...
前端·javascript·npm
2601_9657984717 分钟前
Launch Your Wellness App Fast: The Truth About Meditation Source Code
前端·macos·ios·objective-c·cocoa
周小董36 分钟前
[1367]npm 安装 canvas 报错 node-gyp ERR
前端·npm·node.js
智脑API37 分钟前
Codex config.toml check_for_update_on_startup 怎么关闭?离线环境与版本提醒排查
运维·服务器·前端
存在的五月雨1 小时前
前端布局-flex
前端
Zzj_tju2 小时前
Tool-Using LLM 论文精读路线:从 ReAct 到可验证工具调用
前端·react.js·前端框架
To_OC9 小时前
别再瞎写 React Router!7 个高频踩坑点一次性讲透
前端·javascript·react.js
岭南灯火11 小时前
前端通用交互式几何编辑器的开发经验
前端·设计模式·架构
岭南灯火11 小时前
前端通用交互式几何编辑器的设计法则 7 - 设计模式与原则
前端·设计模式·架构
岭南灯火11 小时前
前端通用交互式几何编辑器的设计法则 4 - 绘制、悬停与编辑
前端·设计模式·架构