美文网首页
vue2 函数式组件

vue2 函数式组件

作者: 洪锦一 | 来源:发表于2022-08-06 11:13 被阅读0次

创建button.js文件

export default {
  functional: true,
  props: {
    type: {
      type: String,
      required: true
    },
  },
  render(h, context) {
    var type = context.props.type
    return <div class={type}>{type}</div>
  }
}

在父组件引入 import button from "./components/button.js 组件
注册函数组件

export default {
  components: {
     button
  }
}

在页面使用

<template>
    <button type="primary"></button>
    <button type="error"></button>
</template>

css 样式

.primary{color: green;}
.error{color: red;}

相关文章

  • vue2 函数式组件

    创建button.js文件 在父组件引入 import button from "./components/but...

  • React 函数式组件

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

  • React入门(二)

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

  • React - 类组件创建

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

  • React 面向组件编程

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

  • 三.父子组件传值(return很重要)

    父传子(vue2同)props 父组件A (return函数) 子组件B 子传父context.emit tip:...

  • 函数式组件

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

  • Render渲染函数和JSX

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

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

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

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

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

网友评论

      本文标题:vue2 函数式组件

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