primevue-mirror/apps/showcase/doc/dynamicdialog/PassingDataDoc.vue

72 lines
1.7 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
2023-11-02 06:28:24 +00:00
<p>Use the <i>data</i> property to pass parameters when opening a Dialog, the internal component can later access this data using <i>dialogRef</i>.</p>
2023-02-28 08:29:30 +00:00
2024-01-30 08:16:35 +00:00
<DocSectionCode :code="code1" hideToggleCode importCode hideStackBlitz />
<DocSectionCode :code="code2" hideToggleCode importCode hideStackBlitz />
2023-02-28 08:29:30 +00:00
2023-11-02 06:28:24 +00:00
<p>Similarly when hiding a Dialog, any parameter passed to the <i>close</i> function is received from the <i>onClose</i> callback.</p>
2024-01-30 08:16:35 +00:00
<DocSectionCode :code="code3" hideToggleCode importCode hideStackBlitz />
<DocSectionCode :code="code4" hideToggleCode importCode hideStackBlitz />
2023-02-28 08:29:30 +00:00
</DocSectionText>
</template>
<script>
export default {
data() {
return {
code1: {
basic: `
2023-11-02 06:28:24 +00:00
const dialog = useDialog();
const showProducts = () => {
dialog.open(ProductListDemo, {
data: {
user: 'primetime'
}
});
}
2023-09-26 12:14:16 +00:00
`
2023-02-28 08:29:30 +00:00
},
code2: {
2023-09-26 12:14:16 +00:00
basic: `
2023-11-02 06:28:24 +00:00
import { inject, onMounted } from "vue";
const dialogRef = inject('dialogRef');
onMounted(() => {
2023-11-15 17:26:40 +00:00
const params = dialogRef.value.data; // {user: 'primetime'}
2023-11-02 06:28:24 +00:00
})
2023-09-26 12:14:16 +00:00
`
2023-02-28 08:29:30 +00:00
},
code3: {
basic: `
2023-11-02 06:28:24 +00:00
const dialog = useDialog();
const showProducts = () => {
dialog.open(ProductListDemo, {
onClose: (opt) => {
const callbackParams = opt.data; // {selectedId: 12}
}
});
}
2023-09-26 12:14:16 +00:00
`
2023-02-28 08:29:30 +00:00
},
code4: {
2023-09-26 12:14:16 +00:00
basic: `
2023-11-02 06:28:24 +00:00
import { inject } from "vue";
const dialogRef = inject('dialogRef');
const closeDialog = () => {
dialogRef.value.close({
selectedId: 12
});
2023-09-26 12:14:16 +00:00
}
`
2023-02-28 08:29:30 +00:00
}
};
}
};
</script>