0.1.17 • Published 12 months ago
@gopowerteam/vue-modal v0.1.17
Modal Componet For Vue 3
基于Vue 3
的API
式弹窗组件
安装(Install)
npm install @gopowerteam/vue-modal --save
// OR
yarn add @gopowerteam/vue-modal
App.vue
<template>
<modal-provider>
<router-view>
</modal-provider>
</template>
<script lang="ts">
import { ModalProvider } from "@gopowerteam/vue-modal";
export default defineComponent({
components: {
ModalProvider,
}
});
</script>
<style>
// 引入样式文件
// 在vue文件中引入
@import url('~@gopowerteam/vue-modal/dist/style.css');
// 或在ts/js文件中引入
// import '@gopowerteam/vue-modal/dist/style.css'
</style>
使用(Usage)
通过使用useModal
获取modal
对象,然后通过open
方法即可打开弹窗.
import HelloWorld from "../components/HelloWorld.vue";
import { useModal } from "@gopowerteam/vue-modal";
export default defineComponent({
components: {},
setup() {
const modal = useModal();
function onClick() {
modal
.open({
title: "弹窗标题",
component: HelloWorld,
props: {
msg: "123",
}
})
.then((a: any) => {});
}
return {
onClick,
};
API
open
打开弹窗
const modal = useModal()
modal.open(ModalOption)
ModalOption
Name | Type | Default: | Description |
---|---|---|---|
component | VueComponent | - | 弹窗内容组件 |
props | Object | - | 弹窗内容组件的props值 |
title | String | - | 标题 |
header | Boolean | true | 是否显示弹窗标题栏 |
closable | Boolean | true | 是否显示窗口关闭按钮 |
maskClosable | Boolean | true | 点击mask区域是否可以关闭弹窗 |
width | Number/String | - | 窗口宽度 |
close
关闭弹窗
const modal = useModal()
modal.close()
在打开弹窗的组件页面执行modal.close
即可关闭组件所在的弹窗页面
close
的参数将作为回传数据进行返回
modal.close({result:true})
closeAll
关闭所有弹窗
const modal = useModal()
modal.closeAll()
补充
数据回传
modal.open
返回对象为promise
对象,通过then
即可接收回传数据
const modal = useModal()
modal.open(ModalOption).then(data=>{
// 处理回传数据
}})
通过modal.close
即可将数据进行回传
//open
modal.open(...).then(data=>{
console.log(data) // {result:true}
})
// close
modal.close({result:true})
窗体最小宽度
窗体最小宽度可以在modal-provider
上进行设置,默认为500px
<template>
<modal-provider :min-width="800">
...
</template>
0.1.17
12 months ago
0.1.13
1 year ago
0.1.14
1 year ago
0.1.15
1 year ago
0.1.16
12 months ago
0.0.15
1 year ago
0.1.12
2 years ago
0.1.11
2 years ago
0.1.10
3 years ago
0.1.9
3 years ago
0.1.8
3 years ago
0.1.7
3 years ago
0.1.6
3 years ago
0.1.5
3 years ago
0.1.4
3 years ago
0.1.3
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago