2021-04-15 09:43:37    56    0    0

什么是函数式组件

我们可以把函数式组件想像成组件里的一个函数,入参是渲染上下文(render context),返回值是渲染好的HTML

对于函数式组件,可以这样定义:

Stateless(无状态)`:组件自身是没有状态的
Instanceless(无实例):组件自身没有实例,也就是没有this
由于函数式组件拥有的这两个特性,我们就可以把它用作高阶组件(High order components),所谓高阶,就是可以生成其它组件的组件。就像日本的高精度的母机。

下面示例的完整Demo

那创造一个函数式组件吧
functional: true加上render function,就是一个最简单的函数式组件啦,show your the code, 下面就创建一个名为FunctionButton.js的函数式组件

  1. export default {
  2. name: 'functional-button',
  3. functional: true,
  4. render(createElement, context) {
  5. return createElement('button', 'click me')
  6. }
  7. }

就像上文所讲的,函数式组件没有this,参数就是靠context来传递的了,下面我们看下context有哪些属性呢

Render context
props
children
slots (a slots object)
parent
listeners
injections
data

其中上面的data包含了其他属性的引用,nibility。 在下面的范例中会有具体使用

现在创建一个App.vue来引入上面的函数式组件

  1. <template>
  2. <FunctionalButton>
  3. click me
  4. </FunctionButton>
  5. </template>

上面的click me就是FunctionButton.js的childern属性了,我们可以把组件改造下,由App.vue来定义组件的button按钮

2021-04-01 07:49:01    46    0    0

动态缓存组件

  • 使用keep-aliveinclude, 动态控制状态

不能缓存多层级路由

  • 解决: 干掉中间空白路由, 只支持3层路由

    1. 使用include或者exclude
    2. 二级router-view设置组件name属性
    3. router.beforeEach中加入如下代码

      1. if (to.matched && to.matched.length > 2) {
      2. for (let i = 0; i < to.matched.length; i++) {
      3. const element = to.matched[i]
      4. if (element.components.default.name === 'Blank') {
      5. to.matched.splice(i, 1)
      6. }
      7. }
      8. }
2019-11-15 11:00:45    119    0    0
### git仓库: git@服务器地址:路径/xxxx.git **** ## **克隆分支代码** > 选择 `克隆` -> 勾选`分支` -> 填写`分支`名称 ## **合并代码** > 1. **直接合并(merge)**, 注意: `一般是分支和分支间的合并, 如果只想合并一个分支某一个commit的话, 默认会把合并的commit下面所有的commit都合并了`. 2. *
2019-11-15 11:00:44    54    0    0

常用命令图示


拉取指定分支的代码

  1. git clone -b 分支 仓库地址
2019-11-14 07:46:53    15    0    0
### vue-cli3使用vux 1.先卸载vue-cli(旧版) npm uninstall vue-cli -g 2.npm install -g @vue/cli 3.vue create 4.npm run serve(启动服务---可以手机端也可以访问) npm run build(打包) *** - 新建vue.config.js ``` module.expo
2019-11-14 07:46:51    13    0    0
> 地址: https://www.jianshu.com/p/beeb5756836e
2019-11-14 07:46:51    3    0    0
> 参考: https://my.oschina.net/tongjh/blog/1928824
2019-11-14 07:46:48    7    0    0

只能选今天或者今天以后的日期

  1. disabledDate = (current) => {
  2. return current && current < moment().startOf('day').subtract(0, 'days');
  3. }

只能选今天或者今天以后的小时

  1. disabledRangeTime = (_, type) => {
  2. const { form: { getFieldValue } } = this.props
  3. if (type === 'start') {
  4. const nowHours = moment().hours()
  5. const time = getFieldValue("time")
  6. if (time && moment(time[0].format("YYYY-MM-DD")).valueOf() <= moment(moment().format("YYYY-MM-DD")).valueOf()) {
  7. return {
  8. disabledHours: () => this.range(0, nowHours),
  9. };
  10. }
  11. }
  12. }

在关闭选择时间面板的时候判断是否小于(当前时间 + 10s)

  1. onOpenChange = (status) => {
  2. const { form: { getFieldValue, setFields } } = this.props
  3. const time = getFieldValue("time")
  4. if (!status) {
  5. if (time && (moment(time[0]).valueOf() + 10000) < moment().valueOf()) {
  6. setFields({
  7. time: {
  8. value: null,
  9. errors: [n
2019-11-14 07:46:48    13    0    0
> https://ant.design/docs/react/recommendation-cn
2019-11-14 07:46:48    17    0    0
### 高度样式 this.setState({ showInfoDetail: false, protocolInfo: null })} footer={[ , ]} >
7/19