我正在切换一个元素,在那个时候,想绑定样式另一个元素。但我不知道如何用@click
实现这一点
data(){
return {
show:false,
filterStyle: {
top: 0,
background: "#dfe4ea",
marginTop: "15px",
marginBottom: "15px",
},
}
}
methods: {
closing(){
this.show = !this.show
},
}
<p class="closeMap" @click="closing()">close</p>
关闭div以下.
<div v-show="!show"></>
更改样式( div )在.下面
<div :style="filterStyle" class="filter"></div>
有人能解释给我听吗?
编辑:顺便说一句,正如你所看到的,我正在绑定我的风格,没有问题。但不是@click
..。我想通过@click
绑定这些样式。
发布于 2019-06-04 00:33:30
我不知道您是否想在show
或!show
上添加样式,不管怎样,您可以通过以下方式实现:
<div :style="show ? filterStyle : null" class="filter"></div>
只有当filterStyle
是show
时才会应用true
发布于 2019-06-04 00:33:31
我想您可以创建一个计算属性,它基于this.show
进行更改。
// Template
<div :style="filterStyle" class="filter"></div>
// Computed property
computed: {
filterStyle() {
if (this.show) {
return {
top: 0,
background: '#dfe4ea',
marginTop: '15px',
marginBottom: '15px'
};
} else {
return '';
}
}
}
还可以在click函数中将filterStyle
设置为其他内容。
https://stackoverflow.com/questions/56439880
复制相似问题