[Vue @Component] Write Vue Functional Components Inline

Vue's functional components are small and flexible enough to be declared inside of .vue file next to the main component. This allows you to mix jsx and Vue's templates so you have complete control over how to render your content.

 

Robot.vue:

复制代码
<script>
export default {
    functional: true,
    render: (h, {props, data}) => {
        return props.names.map(
            name => `https://robohash.org/${name}?set=set${props.num}`
        ).map(
            url => <div><img src={url} alt="" /></div>
        );
    }
}
</script>
复制代码

 

Using:

复制代码
<template>
       <section slot="content" class="flex flex-row flex-no-wrap">
          <Robot :names="names" :num="2"></Robot>
        </section>
</template>

<script>
@Component({
  components: {
    Layout,
    Settings,
    Robot
  }
})
export default class HelloWorld extends Vue {
  @Prop({
    default: ["mindy", "john", "kim", "joel", "ben"]
  }) names
}
</script>
复制代码

 

posted @   Zhentiw  阅读(349)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-07-25 [Nuxt] Display Vuex Data Differently in Each Page of Nuxt and Vue.js
2017-07-25 [Nuxt] Update State with Vuex Actions in Nuxt.js
2017-07-25 [Nuxt] Use Vuex Actions to Delete Data from APIs in Nuxt and Vue.js
2017-07-25 [Nuxt] Build a Vue.js Form then use Vuex Actions to Post to an API in Nuxt
2017-07-25 [Nuxt] Build a Navigation Component in Vue.js and Use in a Nuxt Layout
2016-07-25 [GIF] Colors in GIF Loop Coder
2016-07-25 [React Native] Passing data when changing routes
点击右上角即可分享
微信分享提示