<template>
<div class="notification fixed"
v-if="show"
transition="slide">
<div class="delete"
@click="close()"></div>
<div class="content">
{{ options.content }}
</div>
</div>
</template>
<script>
export default {
props: {
options: {
type: Object,
default: () => {
return {}
}
},
show: {
type: Boolean,
default: false
}
},
methods: {
close () {
this.show = false
this.options = {}
}
}
}
</script>
<style scoped lang="sass">
.slide-transition
transition: all .3s ease
transform: translate3d(0, 0, 0)
.slide-enter,
.slide-leave
transform: translate3d(0, -100%, 0)
.delete
-moz-appearance: none
-webkit-appearance: none
background: rgba(51,51,51,0.2)
cursor: pointer
display: inline-block
height: 24px
position: relative
vertical-align: top
width: 24px
float: right
&:before,
&:after
background: #fff
content: ""
display: block
height: 2px
left: 50%
margin-left: -25%
margin-top: -1px
position: absolute
top: 50%
width: 50%
&:before
transform: rotate(45deg)
&:after
transform: rotate(-45deg)
&:hover
background: rgba(51,51,51,0.5)
.notification
width: 100%
line-height: 2
z-index: 3
position: fixed
top: 0
left: 0
.content
padding: .75rem 2rem
</style>
computed: {
setStyle () {
return {
color: this.options.textColor || '#fff',
background: this.options.backgroundColor || '#21e7b6'
}
}
}
data () {
return {
timers: []
}
},
methods: {
countdown () {
if (this.options.autoClose) {
const t = setTimeout(() => {
this.close()
}, this.options.showTime || 3000)
this.timers.push(t)
}
}
},
watch: {
options () {
this.timers.forEach((timer) => {
window.clearTimeout(timer)
})
this.timers = []
this.countdown()
}
}
// store.js
const state = {
show: false,
options: {
autoClose: false,
content: 'notice content'
}
}
const mutations = {
NEW_NOTICE (state, options) {
state.show = true
state.options = options
},
CLOSE_NOTICE (state) {
state.show = false
state.options = {}
}
}
// actions.js
export const newNotice = ({dispatch}, options) => {
dispatch('NEW_NOTICE', options)
}
export const closeNotice = ({dispatch}) => {
dispatch('CLOSE_NOTICE')
}
// Notification.vue
vuex: {
getters: {
show: state => state.show
options: state => state.options
},
actions: {
close: closeNotice
}
}
// 任意调用notice的组件
vuex: {
actions: {
notice: newNotice
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有