Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vue-template-promise

> 编程语言
Open source

Template as Promise in Vue

374 stars0 likes0 views
WebsiteGitHub

About

Template as Promise in Vue

** This package is now part of VueUse v10**.

Refer to https://vueuse.org/createTemplatePromise instead.


Legacy README

vue-template-promise

Template as Promise in Vue. Useful for constructing custom Dialogs, Modals, Toasts, etc.

Why?

xml

  
    
    OK
  

Features

  • ‍ Programmatic - call your UI as a promise

  • Template - use Vue template to render, not a new DSL

  • TypeScript - full type safety via generic type

  • ⚪️ Renderless - you take full control of the UI

  • Lightweight - only

    OK


Learn more about [Vue Transition](https://v3.vuejs.org/guide/transitions-overview.html).

## Thanks

Thanks to [@johnsoncodehk](https://github.com/johnsoncodehk) for making Volar and the help to make it type safe.

## FAQ

### Why?

The common approach to call a dialog or a model programmatically would be like this:

```ts
const dialog = useDialog()
const result = await dialog.open({
  title: 'Hello',
  content: 'World',
})

This could work nicely by sending those infomation to top level component and let it render the dialog. However, it limits the flexibility you could express in the UI. For example, if you want the title to be red, if you want extra buttons, etc. You might end up with a lot of options like:

typescript
const result = await dialog.open({
  title: 'Hello',
  titleClass: 'text-red',
  content: 'World',
  contentClass: 'text-blue text-sm',
  buttons: [
    { text: 'OK', class: 'bg-red', onClick: () => {} },
    { text: 'Cancel', class: 'bg-blue', onClick: () => {} },
  ],
  // ...
})

Even this is not flexible enough. If you want more, you might end up with manual render function.

typescript
const result = await dialog.open({
  title: 'Hello',
  contentSlot: () => h(MyComponent, { content }),
})

This is like reinventing a new DSL in the script to express the UI template.

So this library is introduce to express the UI in Vue's template instead of the script, as where they are supposed to be, and being able to be called programmatically.

VueUse?

Yes: https://vueuse.org/createTemplatePromise/

Sponsors

License

MIT License © 2022 Anthony Fu

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言