美文网首页
函数式组件

函数式组件

作者: 泪滴在琴上 | 来源:发表于2021-01-08 10:24 被阅读0次

函数式组件是无状态,它无法实例化,没有任何的生命周期和方法。创建函数式组件也很简单,只需要在模板添加 functional 声明即可。一般适合只依赖于外部数据的变化而变化的组件,因其轻量,渲染性能也会有所提高。

组件需要的一切都是通过 context 参数传递。它是一个上下文对象,具体属性查看文档。这里 props 是一个包含所有绑定属性的对象。

函数式组件

<template functional>
    <div class="list">
        <div class="item" v-for="item in props.list" :key="item.id" @click="props.itemClick(item)">
            <p>{{item.title}}</p>
            <p>{{item.content}}</p>
        </div>
    </div>
</template>

父组件使用

<template>
    <div>
        <List :list="list" :itemClick="item => (currentItem = item)" />
    </div>
</template>
import List from '@/components/List.vue'
export default {
    components: {
        List
    },
    data() {
        return {
            list: [{
                title: 'title',
                content: 'content'
            }],
            currentItem: ''
        }
    }
}

相关文章

  • React 函数式组件

    简单函数式组件 使用 hook 的函数式组件

  • React入门(二)

    组件 1.函数式组件 什么是函数式组件创建一个函数,只要函数中返回一个新的JSX元素,则为函数式组件 调用组件可以...

  • React - 类组件创建

    React创建组件有两种方式 函数式组件 类组件函数式组件已经学过,现在看下类组件怎么写。 函数式组件和类组件区别...

  • React 面向组件编程

    函数式组件// 创建函数式组件function MyComponent() {console.log(this)/...

  • 函数式组件

    函数式组件 函数式组件,即无状态,无法实例化,内部没...

  • Render渲染函数和JSX

    render函数 h( 元素,属性,值 ) 中 h 不能少 使用 list组件中调用 函数式组件 定义函数式组件 ...

  • recompose函数式库 + ( git? ) + ( vo

    (一) recompose 函数式组件,高阶组件库 (1) withState 因为函数式组件中没有state,但...

  • Vue.js 2函数式组件学习

    什么是函数式组件? 函数式组件就是函数是组件,组件是函数,它的特征是没有内部状态、没有生命周期钩子函数、没有thi...

  • 1-5 函数式组件

    demo1 - 函数式组件 demo2 - 类组件 demo3 - 函数式组件传参 组件里面套组件 - 复合组件 ...

  • 笔记-React-Hooks

    一、矛与盾的问题?(Class组件与函数式组件)   在 React 中 Class 组件好用还是函数式组件好用呢...

网友评论

      本文标题:函数式组件

      本文链接:https://www.haomeiwen.com/subject/ewrtaktx.html