vue-final / vue-final-modal

🍕Vue Final Modal is a tiny, renderless, mobile-friendly, feature-rich modal component for Vue.js.
https://vue-final-modal.org
MIT License
903 stars 97 forks source link

Dynamic attrs (props) #357

Closed xaja closed 1 year ago

xaja commented 1 year ago

from v-if loop i want to open popup with item prop, something like that:

in template:

<tr
  v-for="item in items"
  :key="item.id"
  class="cursor-pointer"
  @click="openWarningsPopupItem(item)" // ???
>

in script:

const { open: openWarningsPopupItem } = useModal({
  component: WarningsPopupItem,
  attrs: {
     item: // ???
  },
});

is there solution to do that in this version of VFM?

hunterliu1003 commented 1 year ago

@xaja Yes, please follow the documentation here: https://vue-final-modal.org/api/composables/use-modal#passing-props-and-events

JshGrn commented 12 months ago

@hunterliu1003 I do not believe this is answered, how can I access 'item' which is passed into the open function?

Firstasianinspace commented 10 months ago

May be we are noobs, but i also don't see how can i pass dynamic props. I got a payload from v-for item, then modal opens with undefined props

JshGrn commented 10 months ago

I solved this by making sure that the item passed in the attrs was a computed prop, e.g.

attrs: {
    item: computed(() => state.valuehere)
}

Then in the modal in script setup used

 defineProps({
      item: {
          required: true
      }
 });

Without it being computed it wasn't reactive, I do not think the examples and the docs are very clear on this at all. You can then post back to the onConfirm method using defineEmits for communication from the modal.