primevue-mirror/apps/showcase/doc/message/DynamicDoc.vue

117 lines
3.8 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>Multiple messages can be displayed using the standard v-for directive.</p>
</DocSectionText>
2024-06-12 22:05:19 +00:00
<div class="card flex flex-col items-center justify-center gap-4">
<div class="flex gap-2">
<Button label="Show" @click="addMessages()" />
<Button label="Clear" severity="secondary" @click="clearMessages()" />
</div>
2024-06-13 08:04:57 +00:00
<transition-group name="p-message" tag="div" class="flex flex-col">
<Message v-for="msg of messages" :key="msg.id" :severity="msg.severity" class="mt-4">{{ msg.content }}</Message>
2023-02-28 08:29:30 +00:00
</transition-group>
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
messages: [],
count: 0,
code: {
2023-09-22 12:54:14 +00:00
basic: `
<Button label="Show" @click="addMessages()" />
2023-03-03 12:15:20 +00:00
<Button label="Clear" severity="secondary" class="ml-2" @click="clearMessages()" />
2024-06-13 08:04:57 +00:00
<transition-group name="p-message" tag="div" class="flex flex-col">
<Message v-for="msg of messages" :key="msg.id" :severity="msg.severity" class="mt-4">{{ msg.content }}</Message>
2023-10-15 09:38:39 +00:00
</transition-group>
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2024-06-12 22:05:19 +00:00
<div class="card flex flex-col items-center justify-center gap-4">
<div class="flex gap-2">
<Button label="Show" @click="addMessages()" />
<Button label="Clear" severity="secondary" @click="clearMessages()" />
</div>
2024-06-13 08:04:57 +00:00
<transition-group name="p-message" tag="div" class="flex flex-col">
<Message v-for="msg of messages" :key="msg.id" :severity="msg.severity" class="mt-4">{{ msg.content }}</Message>
2023-03-03 12:15:20 +00:00
</transition-group>
2023-02-28 08:29:30 +00:00
</div>
</template>
<script>
export default {
data() {
return {
messages: [],
count: 0
};
},
methods: {
addMessages() {
this.messages = [
{ severity: 'info', content: 'Dynamic Info Message', id: this.count++ },
{ severity: 'success', content: 'Dynamic Success Message', id: this.count++ },
2024-05-08 11:35:11 +00:00
{ severity: 'warn', content: 'Dynamic Warn Message', id: this.count++ }
2023-02-28 08:29:30 +00:00
];
},
clearMessages() {
this.messages = [];
}
}
};
}
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2024-06-12 22:05:19 +00:00
<div class="card flex flex-col items-center justify-center gap-4">
<div class="flex gap-2">
<Button label="Show" @click="addMessages()" />
<Button label="Clear" severity="secondary" @click="clearMessages()" />
</div>
2024-06-13 08:04:57 +00:00
<transition-group name="p-message" tag="div" class="flex flex-col">
<Message v-for="msg of messages" :key="msg.id" :severity="msg.severity" class="mt-4">{{ msg.content }}</Message>
2023-03-03 12:15:20 +00:00
</transition-group>
2023-02-28 08:29:30 +00:00
</div>
</template>
<script setup>
import { ref } from 'vue';
const messages = ref([]);
let count = ref(0);
const addMessages = () => {
messages.value = [
{ severity: 'info', content: 'Dynamic Info Message', id: count.value++ },
{ severity: 'success', content: 'Dynamic Success Message', id: count.value++ },
2024-05-08 11:35:11 +00:00
{ severity: 'warn', content: 'Dynamic Warn Message', id: count.value++ }
2023-02-28 08:29:30 +00:00
];
};
const clearMessages = () => {
messages.value = [];
};
2023-10-15 09:38:39 +00:00
<\/script>
`
2023-02-28 08:29:30 +00:00
}
};
},
methods: {
addMessages() {
this.messages = [
{ severity: 'info', content: 'Dynamic Info Message', id: this.count++ },
{ severity: 'success', content: 'Dynamic Success Message', id: this.count++ },
2024-05-08 11:35:11 +00:00
{ severity: 'warn', content: 'Dynamic Warn Message', id: this.count++ }
2023-02-28 08:29:30 +00:00
];
},
clearMessages() {
this.messages = [];
}
}
};
</script>