Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue hoc不显示插槽 #307

Open
Envov opened this issue Jul 30, 2021 · 1 comment
Open

vue hoc不显示插槽 #307

Envov opened this issue Jul 30, 2021 · 1 comment

Comments

@Envov
Copy link

Envov commented Jul 30, 2021

vue hoc那边$slots里面的vnode是数组不是对象

.map(vnode => {
          vnode.context = this._self
          return vnode
        })

vnode是一个数组,改为⬇️

.map(vnodes => {
          vnodes.forEach(vnode => (vnode.context = this._self));
          return vnodes
        })
@Envov
Copy link
Author

Envov commented Jul 30, 2021

//成功代码

import * as R from "ramda";
//重载vnodes的方式
const how2ReloadVnodes = that =>
  R.compose(R.forEach(vnode => (vnode.context = that._self)));
//用xxxxx组合slots
const composeSlotsWith = how => fromWho =>
  R.compose(R.map(how(fromWho)), R.values);

export const WithConsole = something => WrappedComponent => {
  return {
    mounted() {
      console.log(`I have already ${something}`);
    },
    props: WrappedComponent.props,
    render(createElement) {
      const { $slots, $listeners, $props, $scopedSlots, $attrs } = this;
      const slots = composeSlotsWith(how2ReloadVnodes)(this)($slots);
      // 什么是vue的 h(createElement)函数 见 https://segmentfault.com/a/1190000020526322*/
      return createElement(
        WrappedComponent,
        {
          on: $listeners,
          props: $props,
          scopedSlots: $scopedSlots,
          attrs: $attrs,
        },
        slots
      );
    },
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant