DEV Community

Cover image for Ionic Modal In Vue JS, Managing Events

Ionic Modal In Vue JS, Managing Events

Aaron K Saunders on March 21, 2020

This post is kinda old, there is a full example on using IonModal Here No TS Ionic Vue Example If you have issues let me know. - The Ionic Comp...
Collapse
 
davids89 profile image
David

It is possible to bind props with a new modal instance?

Collapse
 
aaronksaunders profile image
Aaron K Saunders • Edited

not sure I understand the question?

Also, I don't create modals this way anymore, I use the template approach, I find it to be much cleaner

Take a look here: github.com/aaronksaunders/ionic-vu...

Collapse
 
suzannevangelder profile image
Suzanne-van-Gelder

I think David means data: { name: "Why Data" } in Detail.vue does not bind to the props in SimpleModal.vue. The default values are used in the Modal.

I have the same problem and get the warning:
[Vue warn]: Extraneous non-props attributes (data) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.

I tried to figure it out myself, but am a little bit stuck by now.

Thread Thread
 
aaronksaunders profile image
Aaron K Saunders

have you looked at the updated code sample referenced above? This post is over a year old and ionic has changed how they manage modals. If you have a code sample project somewhere I am happy to take a look

Thread Thread
 
suzannevangelder profile image
Suzanne-van-Gelder

Yes, I have cloned the project with updated code from github.com/aaronksaunders/ionic-vu....

I have changed
data: {
name: "Why Data"
}
into
data: {
title: "Why Data"
}
but both do not show "Why Data" in the title of the modal, but "Super Modal" instead.

I run Ionic Framework : @ionic/vue 5.5.2 with vue@3.0.4

Thread Thread
 
aaronksaunders profile image
Aaron K Saunders

to change the title of the modal, you need to set the modals title property, you are changing the data property which has no impact on the modal

Thread Thread
 
suzannevangelder profile image
Suzanne-van-Gelder

I think you mean:
props: {
title: { type: String, default: "Super Modal" }
},
But how do I change this using parameters from detail.vue?

Thread Thread
 
aaronksaunders profile image
Aaron K Saunders
    <simple-modal
      :title="data"
      @modalSave="handleSave"
      @modalCancel="handleCancel">
    </simple-modal>
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
suzannevangelder profile image
Suzanne-van-Gelder

Thank you, it's working now.

Thread Thread
 
aaronksaunders profile image
Aaron K Saunders

Thanks, please like and subscribe to my YouTube channel, trying to get my subscribers over 2000!! And you will get updated when I push new content

Collapse
 
ideasdelaboratorio profile image
ideasdelaboratorio

How can it be adapted to be able to call the modal from any other component?
Thanks

Collapse
 
aaronksaunders profile image
Aaron K Saunders

i dont this that is how component based frameworks are meant to work. You should put the contents of the modal in a separate component that can be utilized on different locations in your app

Collapse
 
ideasdelaboratorio profile image
ideasdelaboratorio

Thanks. I meant the modal component to avoid the import in every component it's called. The content of the modal differs if arrive from one button or link.
Vuejs Event bus can be used in ionic?

Thread Thread
 
aaronksaunders profile image
Aaron K Saunders

yes Ionic just provides web components, all the regular vue stuff is still there

Collapse
 
visibly profile image
visibly

Thanks for the example. Have you succeeded to add swipeToClose to modals?
I'm having issues getting this to work, but I don't know if it's even supported in the Ionic Vue beta?

For reference this is my method for opening the modal (which works perfectly fine - except for the swipeToClose):

openTaskDrawer(task) { return this.modal = this.$ionic.modalController .create({ component: TaskDrawer, presentingElement: this.$el, swipeToClose: true, componentProps: { propsData: { task: task } }, }) .then(m => m.present()) }

Collapse
 
aaronksaunders profile image
Aaron K Saunders

tryed to make a video, but jacked up the sound... here it is for now until i get a chance to redo the video track youtu.be/nEkJWKSXcDM