carousel-3d(:display="3", :width="150", :height="150")
我想根据媒体查询设置属性绑定(bind)
例如
当屏幕宽度 > 960px 时显示应变为 5
最佳答案
您可以尝试将 display 值绑定(bind)到组件属性:
<carousel-3d :display="display">
...然后在调整窗口大小时更新该属性:
...
data() {
return {
display: 3
}
},
methods: {
onResize() {
if (window.innerWidth > 960) {
this.display = 5
} else {
this.display = 3
}
}
},
created() {
window.addEventListener('resize', this.onResize)
},
beforeDestroy() {
window.removeEventListener('resize', this.onResize)
},
...
关于css - vue 基于媒体查询的绑定(bind)值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47143204/