carousel-3d(:display="3", :width="150", :height="150")
我想根据媒体查询设置属性绑定
例如
display should become 5 when screen width > 960px
carousel-3d(:display="3", :width="150", :height="150")
我想根据媒体查询设置属性绑定
例如
display should become 5 when screen width > 960px
可以try 将display值绑定到组件属性:
<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)
},
...