data: () => ({
width: 0,
}),
computed: {
itemSize() {
return this.width > 700 ? 46 : 56;
},
},
methods: {
onResize() {
this.width = window.innerWidth;
},
},
created() {
this.onResize();
window.addEventListener('resize', this.onResize);
},
beforeDestroy() {
window.removeEventListener('resize', this.onResize);
},
// или
data: () => ({
itemSize: null,
}),
created() {
const mql = window.matchMedia('(max-width: 700px)');
const onChange = () => this.itemSize = mql.matches ? 56 : 46;
onChange();
mql.addEventListener('change', onChange);
this.$on('hook:beforeDestroy', () => mql.removeEventListener('change', onChange));
},
:item-size="itemSize"