npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue3-teleport-mount

v0.0.3

Published

Similar to the built-in Vue3 component `<Teleport>`, it renders components functionally to a specified location, solving the problem that when rendering components functionally, the components cannot obtain the `provide` values of their ancestor component

Downloads

175

Readme

vue3-teleport-mount

Similar to the built-in Vue3 component <Teleport>, it renders components functionally to a specified location, solving the problem that when rendering components functionally, the components cannot obtain the provide values of their ancestor components.

English | 中文

Installation

npm install vue3-teleport-mount
# Or use pnpm
pnpm install vue3-teleport-mount

Usage

1. Register the Plugin TeleportPlugin

import { TeleportPlugin } from 'vue3-teleport-mount'

const app = createApp(App)
app.use(TeleportPlugin)

2. Set the "Teleport" Outlet <TeleportView />

<script setup>
import { TeleportView } from 'vue3-teleport-mount'
</script>

<template>
  <el-config-provider namespace="my-el">
    <TeleportView />
  </el-config-provider>
</template>

Example

<script setup lang="tsx">
import { useTeleport } from 'vue3-teleport-mount'

const { mount, unmount, getInstance } = useTeleport(
  defineAsyncComponent(() => import('./MyComponent.vue')), // Import the component via defineAsyncComponent to optimize performance.
)

const show = async () => {
  const res = await mount({
    title: 'Title', // Pass the props of the component.
  })
  res?.sayHi() // Call the component method.
}
</script>

<template>
  <el-button @click="show">
    Show
  </el-button>
  <el-button @click="unmount">
    Unmount
  </el-button>
</template>

Type Definitions

useTeleport

function useTeleport<T extends Component>(
  Comp: T,
  to?: string | symbol
): {
  getTeleportInstance: () => InstanceType<T> | undefined;
  mount: (props?: unknown) => Promise<InstanceType<T> | undefined;
  unmount: () => void;
}

TeleportView

  • Props
interface TeleportViewProps {
  /**
   * Container Name
   * Default Value: default
   */
  name?: string | symbol
}
  • Example
<!-- Set the container name to the default value: default -->
<TeleportView />
<!-- Set the container name to: my-name -->
<TeleportView name="my-name" />
<script setup lang="tsx">
import { useTeleport } from 'vue3-teleport-mount'
import MyComponent from './MyComponent.vue'
import MyComponent2 from './MyComponent2.vue'

const { mount } = useTeleport(MyComponent) // "Teleport" to <TeleportView/>
const { mount: mount2 } = useTeleport(MyComponent2, 'my-name') // "Teleport" to <TeleportView name="my-name" />


</script>

<template>
  <el-button @click="mount">
    Show Component 1
  </el-button>
  <el-button @click="mount2">
    Show Component 2
  </el-button>

</template>