<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
.toast {
position: fixed;
z-index: 2000;
left: 50%;
top: 45%;
transition: all .5s;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
text-align: center;
border-radius: 5px;
color: #FFF;
background: rgba(17, 17, 17, 0.7);
height: 45px;
line-height: 45px;
padding: 0 15px;
max-width: 150px;
}
</style>
<body>
<!-- 提示框 -->
<div id="app">
<div @click="binxs">
{{username}}
</div>
<div class="toast" v-show="toastShow">
{{toastText}}
</div>
</div>
<script src="../js/vue.js" type="text/javascript" charset="utf-8">
</script>
<script>
const obj = {
toastShow: false,
toastText: '',
username: '显示消息提示框'
}
const app = new Vue({
el: '#app',
data: obj,
methods: {
toast(str) {
let v = this
v.toastText = str
v.toastShow = true
setTimeout(function() {
v.toastShow = false
}, 1500)
},
binxs: function(e) {
this.toast('显示成功')
}
}
})
</script>
</body>
</html>
08-13