Skip to content

Commit

Permalink
修复多个snackbar同时出现的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
memset0 committed Sep 26, 2024
1 parent 8125b81 commit df1e9ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import DialogBuy from './DialogBuy.vue';
import DialogOption from './DialogOption.vue';
onMounted(() => {
createSnackbar('Hello World');
{
const dialog = document.getElementById("options-dialog");
console.log('!', dialog);
Expand Down
6 changes: 6 additions & 0 deletions src/snackbar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
let lastSnackbar = null;

export function createSnackbar(message) {
const $element = document.createElement('mdui-snackbar');
$element.setAttribute('auto-close-delay', '1000');
$element.setAttribute('class', 'example-close-delay');
$element.innerHTML = message;
document.body.appendChild($element);
$element.open = true;
if (lastSnackbar !== null) {
lastSnackbar.open = false;
}
lastSnackbar = $element;
return $element;
}

0 comments on commit df1e9ac

Please sign in to comment.