console
<div id="app" v-cloak>
<div class="mian" v-clickouteside="handleClose">
<button @click="show = !show">点击显示下拉菜单</button>
<div class="dropdown" v-show="show">
<p>下拉框的内容,点击外面区域可以关闭</p>
</div>
</div>
</div>
<script>
Vue.directive('clickouteside',{
bind:function(el,binding,vnode){
function documentHandler(e){
if(el.contains(e.target)){
return false
}
if(binding.expression){
binding.value(e)
}
}
el.__vueClickOutside__ = documentHandler
document.addEventListener('click',documentHandler)
},
unbind:function(el,binding){
document.removeEventListener('click',el.__vueClickOutside__)
delete el.__vueClickOutside__
}
})
const app = new Vue({
el:'#app',
data:{
show:false
},
methods:{
handleClose:function(){
console.log('show',this.show)
this.show = false
}
}
})
</script>
html, body{
margin: 0;
padding: 0;
height: 100%;
color: #657180;
font-size: 16px;
}
.daily-menu{
width: 150px;
position: fixed;
top: 0;
bottom: 0;
left: 0;
overflow: auto;
background: #f5f7f9;
}
.daily-menu-item{
font-size: 18px;
text-align: center;
margin: 5px 0;
padding: 10px 0;
cursor: pointer;
border-right: 2px solid transparent;
transition: all .3s ease-in-out;
}
.daily-menu-item:hover{
background: #e3e8ee;
}
.daily-menu-item.on{
border-right: 2px solid #3399ff;
}
.daily-menu ul{
list-style: none;
}
.daily-menu ul li a{
display: block;
color: inherit;
text-decoration: none;
padding: 5px 0;
margin: 5px 0;
cursor: pointer;
}
.daily-menu ul li a:hover, .daily-menu ul li a.on{
color: #3399ff;
}
.daily-list{
width: 300px;
position: fixed;
top: 0;
bottom: 0;
left: 150px;
overflow: auto;
border-right: 1px solid #d7dde4;
}
.daily-date{
text-align: center;
margin: 10px 0;
}
.daily-item{
display: block;
color: inherit;
text-decoration: none;
padding: 16px;
overflow: hidden;
cursor: pointer;
transition: all .3s ease-in-out;
}
.daily-item:hover{
background: #e3e8ee;
}
.daily-img{
width: 80px;
height: 80px;
float: left;
}
.daily-img img{
width: 100%;
height: 100%;
border-radius: 3px;
}
.daily-title{
padding: 10px 5px 10px 90px;
}
.daily-title.noImg{
padding-left: 5px;
}
.daily-article{
margin-left: 450px;
padding: 20px;
}
.daily-article-title{
font-size: 28px;
font-weight: bold;
color: #222;
padding: 10px 0;
}
.view-more a{
display: block;
cursor: pointer;
background: #f5f7f9;
text-align: center;
color: inherit;
text-decoration: none;
padding: 4px 0;
border-radius: 3px;
}
.daily-comments{
margin: 10px 0;
}
.daily-comments span{
display: block;
margin: 10px 0;
font-size: 20px;
}
.daily-comment{
overflow: hidden;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px dashed #e3e8ee;
}
.daily-comment-avatar{
width: 50px;
height: 50px;
float: left;
}
.daily-comment-avatar img{
width: 100%;
height: 100%;
border-radius: 3px;
}
.daily-comment-content{
margin-left: 65px;
}
.daily-comment-name{
}
.daily-comment-time{
color: #9ea7b4;
font-size: 14px;
margin-top: 5px;
}
.daily-comment-text{
margin-top: 10px;
}