百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
V

vue-template-promise

> 编程语言
开源

在 Vue 中的模板作为承诺

374 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

在 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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

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