You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found that it is challenging to open a Modal (or other components with programmatic open; e.g., Toast) from a setup script; i.e., inside <script setup>...</script>. The problem is twofold:
Since this is not available in a setup script, we cannot simply do:
<script setup>
import { ModalProgrammatic } from'@ntohq/buefy-next'constopenModal= () => {ModalProgrammatic.open({ ... }) // Error: ModalProgrammatic is not an instance but a class}
</script>
A workaround is to use Vue's internal API (getCurrentInstance) and field (proxy).
<script setup>
import { getCurrentInstance } from'vue'// https://stackoverflow.com/a/68958963constself=getCurrentInstance() // calling getCurrentInstance inside openModal won't work; end up with nullconstopenModal= () => {self.proxy.$buefy.modal.open({ ... }) // self.proxy is kind-of equivalent to this}
</script>
Proposal
I do not think it is a good idea to force users to explicitly depend on internal APIs. So I suggest introducing new composition APIs like useModal in place of ModalProgrammatic:
import{getCurrentInstance}from'vue'exportconstuseModal=()=>{constself=getCurrentInstance()constopen=(props)=>{self.proxy.$buefy.modal.open(props)}return{ open }}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I found that it is challenging to open a Modal (or other components with programmatic
open
; e.g.,Toast
) from a setup script; i.e., inside<script setup>...</script>
. The problem is twofold:Since
this
is not available in a setup script, we cannot simply do:Importing
ModalProgrammatic
no longer works (due to Fix: No plugins available on programmatically opened Modal.open (#101) #102):A workaround is to use Vue's internal API (
getCurrentInstance
) and field (proxy
).Proposal
I do not think it is a good idea to force users to explicitly depend on internal APIs. So I suggest introducing new composition APIs like
useModal
in place ofModalProgrammatic
:useModal
will be something similar to:Beta Was this translation helpful? Give feedback.
All reactions