Giter VIP home page Giter VIP logo

vue-mountable's Introduction

Vue Mountable

Vue Mountable is a tiny DOM Library for Vue 3.

Features

• Native Vue 3 Teleport
• Slotting, Events & Props
• use inject and provide
• Mount multiple Children Components
• Mount HTML Tag's
• Support for defineComponent and defineAsyncComponent
• Support for multiple Vue Instances
• Hot-Module Reloading for vite

Usage

Install

npm i vue-mountable -D

Add it to main.js

import { VueMountable } from 'vue-mountable'

// created vue instance
app.use(VueMountable());

Getting Started

// main.vue

<script>
import { useComponent } from 'vue-mountable';
import test from 'components/test.vue';

export default {
	setup() {
		const { mount, destroy } = useComponent();

		function addTest() {
			mount(test, {
				props: {
					message: 'This is a Test Component'
				}
			});
		}

		return {
			addTest
		}
	}
}
</script>
// test.vue
<template>
	<div ref="test">
		{{ message }}

		<button @click.prevent="close">
			Remove Test Component
		</button>
	</div>
</template>

<script>
import { useComponent } from 'vue-mountable';

export default {
	name: 'test', // this needs to be defined
	props: {
		message: String
	},
	setup() {
		const test = ref(null); // template ref
		const { destroy } = useComponent();

		function close() {
			destroy(test.value);
		}

		return {
			close
		}
	}
}
</script>

Examples

Tiny List of what you can do with Mountable:

Configuration

Current available Function Parameters:

const {
	mount, // mount function
	destroy, // destroy function
	destroyAll, // destroy all mounted elements
	id // current app instance id
} = useComponent();

mount(
	/**
	 * Vue Component File
	 * needs to have the "name" attribute
	*/
	component,
	{
		/**
		 * Native Vue Props
		 */

		props: {},

		/**
		 * Vue Children Components
		 * Array with Vue Components or Object array with Mount Options: component, children, props, target, slot
		 * @props {}
		 * @children []
		 * @target string
		 * @slot string
		 */
		children: [],

		/**
		 * Teleportation Target
		 * Can be defined in the loaded component or here
		 * Note: If the component has a target prop, it will override this option
		 * String referencing an DOM Target
		 */
		target : ''
	}
);

destroy(
	/**
	 * DOM Element
	 */

	element
);

Limitations

At the Moment the useComponent Function is only available in the setup Lifecycle. This is due to the usage of inject/provide from Vue 3. Also there is no Devtools Support, but its in the works! That means added Components wont be visible in Devtools for now..

License

MIT License © 2020-2021 Leon Langer

vue-mountable's People

Contributors

subwaytime avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.