Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jin5354/vue-slot-portal

Vue plugin for across-component slot distribution.
https://github.com/jin5354/vue-slot-portal

vue vue-slot vue2

Last synced: 1 day ago
JSON representation

Vue plugin for across-component slot distribution.

Awesome Lists containing this project

README

        

# vue-slot-portal

[![Build Status](https://travis-ci.org/jin5354/vue-slot-portal.svg?branch=master)](https://travis-ci.org/jin5354/vue-slot-portal)
![version](https://img.shields.io/npm/v/vue-slot-portal.svg)
![mit](https://img.shields.io/npm/l/vue-slot-portal.svg)

Vue plugin for across-component slot distribution.

![sample](https://user-images.githubusercontent.com/6868950/57189626-3a1d4700-6f43-11e9-930c-a52371fe0647.png)

## install

```bash
npm i vue-slot-portal
```

## usage

1. define slot routes (key: slotName, value: componentName)

```javscript
import slotPortal from 'vue-slot-portal'

const slotRoutes = {
level5: 'Level5'
}

Vue.use(slotPortal, slotRoutes)
```

2. write slot content anywhich component in your project, with SlotReceiver

```html
// write your slot content anywhere as you need
// someComponent.vue


...



slot content from Index receiver: {{slotProps.test}}



```

3. wrap your component who need the slot content with SlotInjector, when you reference this component.

```html
// Level5.vue



default {{test}}

```

```vue
// the component which references Level5



import Level5 from './Level5.vue'
import slotPortal from 'vue-slot-portal'

export default {
components: {
// hoc
Level5: slotPortal.SlotInjector(Level5)
}
}

```

then, the slot content whose name is 'level5' will be transported to the component whose name is 'Level5', according to the slot routes.

## license

MIT