opp-vue
v1.0.2
Published
Components and Hooks for [Vue](https://vuejs.org).
Downloads
327
Readme
opp-vue
Components and Hooks for Vue.
Installation
Using npm:
$ npm install --save opp-vueDocumentation
usePlugin
Return registered plugin with react hooks.
type usePlugin = (name: string) => Plugin['hooks'];import { registerPlugin, start } from 'opp-core';
import { usePlugin } from 'opp-vue';
const plugin = { name: 'test', hooks: {} };
registerPlugin(plugin);
start();
const Component = (props = {}) => {
usePlugin('test') === plugin.hooks;
return <div>Component</div>;
};PluginRender
PluginRender will render matched plugin with react lifecycle.
type Props = { id: string };
type PluginRender = ComponentType<Props>;mount
PluginRender will do those things:
- Create
HTMLDivElementwithidsame asprops.id; - Use
props.idto find plugin with sameplugin.container; - Run
plugin.mountwith parameters: element (HTMLDivElement), props (propsomitid);
update
PluginRender will do those things:
- Use
props.idto find plugin with sameplugin.container; - Run
plugin.updatewith parameters: props (propsomitid);
unmount
PluginRender will do those things:
- Use
props.idto find plugin with sameplugin.container; - Run
plugin.unmountwith no parameters;
CreatePlugin
Create plugin with React Component.
type CreatePlugin = (Component: ComponentType) => (plugin: Plugin) => Plugin;import { useState } from 'react';
import { PluginRender, createPlugin } from 'opp-vue';
import { ElInput } from 'element-plus';
const plugin = createPlugin(ElInput)({
name: 'input',
container: 'input-element',
});
registerPlugin(plugin);
start();
const Component = (props = {}) => {
const [value, setValue] = useState('');
return (
<PluginRender id="input-element" value={value} onChange={setValue} />
);
};