在做项目时开发了两个插件,一个是透明提示框、另一个是长时间不操作自动返回首页的插件,在这里分享一下。
一、网页透明提示框插件
1.效果(支持同时弹出多个提示)
2.代码以及使用方法
代码:Alert.vue + notify.js
使用方法:
将两个代码文件放到文件夹notify之下,
在mian.js中加入以下代码:
import notify from './notify/notify'
// ...
Vue.use(notify)
在需要弹提示的地方调用Vue的$notify函数即可。
Alert.vue:
<template>
<div>
<div class="alert show" v-if="messages.length!==0">
<ul>
<li v-for="msg in messages" v-html="msg"></li>
</ul>
</div>
</div>
</template>
<script>
export default {
data () {
return {
show: false,
messages: [],
bgColor: ''
}
},
methods: {
notify (msg) {
this.messages.push(msg)
setTimeout(() => {
if (this.messages.length && this.messages[0] === msg) {
this.messages.shift()
}
}, 1000)
}
}
}
</script>
<style scoped>
.alert {
transform: translate(-50%, -100%);