<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h3>Vue Js Toast Notification</h3>
<div v-if="show" class="toast">
<span>{{ message }}</span>
<button class="close-button" @click="hideToast">×</button>
</div>
</div>
<script type="module">
const app = new Vue({
el: "#app",
data() {
return {
show: false,
message: ''
};
},
methods: {
showToast(message, duration = 5000) {
this.message = message;
this.show = true;
setTimeout(() => {
this.hideToast();
}, duration);
},
hideToast() {
this.show = false;
}
},
mounted() {
this.showToast('Toast successfully created')
}
});
</script>
<style scoped>
.toast {
position: fixed;
bottom: 20px;
left: 20px;
background-color: #333;
color: #fff;
padding: 10px;
border-radius: 4px;
display: flex;
align-items: center;
transition: opacity 0.3s ease-in-out;
}
.close-button {
margin-left: 10px;
border: none;
background: transparent;
color: #fff;
font-size: 16px;
cursor: pointer;
}
</style>
</body>
</html>