Jenesius / vue-modal

🖖The progressive and simple modal system for Vue.js v3
https://modal.jenesius.com
MIT License
142 stars 14 forks source link

There is an onBeforeModalClose, can you add an onBeforeModalOpen? #117

Open a982246809 opened 2 months ago

a982246809 commented 2 months ago

There is an onBeforeModalClose, can you add an onBeforeModalOpen?

Jenesius commented 2 months ago

Hello. What functionality would you like to see in onBeforeModalOpen. I'm using onMounted instead, but if there's a need I'll add it. As I understand it, you control the opening of the fashion window in the fashion window itself?

a982246809 commented 2 months ago

我有一个全局状态 switch , 当switch=false时 , 我希望在全局任意的调用都不会生效 I have a global state switch. When switch=false, I hope that any global call openModalwill not take effect.

Jenesius commented 2 months ago

Okay, I will add it today!

a982246809 commented 2 months ago

可能在vue文件中加onBeforeModalOpen 并不起作用 , 因为一开始并不会初始化 Adding onBeforeModalOpen to the vue file may not work, because it will not be initialized at first

Jenesius commented 2 months ago

It will looks like it:

import {config} from "jenesius-vue-modal"

config({
  beforeEach() {
    if (global.switch === false) return false;
  }
})

How do you like it? Or add just:

import {beforeEach} from "jenesius-vue-modal"

But this is too general a function, I don't want to clutter up the import space

Jenesius commented 2 months ago

Please note version 1.11.7. I added the beforeEach function to the config.

import {config} from "jenesius-vue-modal"

config({
  beforeEach() {
    if (global.switch === false) return false;
  }
})

Thanks for your help in improving the library!

a982246809 commented 2 months ago

thanks , This library is great.

a982246809 commented 1 month ago

Can each Modal be managed individually? For example: 可以对每个Modal进行单独的管理吗 , 例如

config({
    store: {
    Foo: {
       component:FooComp ,
       beforeEach() {
          if (global.switch === false) return false;
        }
    }
   }
})
a982246809 commented 1 month ago

@Jenesius

Jenesius commented 1 month ago

In this case, it is important to understand that this hook will only work when called by name.

I'll try to come up with something and write about it as I go along

a982246809 commented 1 month ago

Can each Modal be managed individually? For example:每个Modal可以单独管理吗?例如: 可以对每个Modal进行单独的管理吗 , 例如

config({
    store: {
    Foo: {
       component:FooComp ,
       beforeEach() {
          if (global.switch === false) return false;
        }
    }
   }
})

backgroundClose also needs to be configured for a separate modal backgroundClose 也需要对单独的modal进行配置

Jenesius commented 1 month ago

I'll try to show the result tomorrow, as long as I have this interface:

export interface IStoreComponentConfiguration {
    component: Component,
    beforeEach: unknown,
    backgroundClose: unknown,
    scrollLock: unknown,
    animation: unknown,
    escClose: unknown,
    draggable: unknown,
}
config({
  store: {
    Foo: IStoreComponentConfiguration 
  }
})
Jenesius commented 1 month ago

Now will available only draggable, beforeEach, backgroundClose. The rest will also need to be taken out, but they are not yet located inside the modal window, but are taken directly from the configuration.

Jenesius commented 1 month ago

Version 1.11.9. Docs

config({
    store: {
        Foo: {
           component:FooComp ,
           beforeEach() {
              if (global.switch === false) return false;
            }
        }
   }
})