我正在使用Enquire.js和Vue.js来查询浏览器的大小并相应地更新两个数据属性。所以,如果我这样做:
ready: function() {
// Listen for changes in the browser's size
window.addEventListener("resize",
enquire.register("screen and (max-width:400px)", {
match: function() {
this.displayIsLarge = false;
this.displayIsSmall = true;
console.log("the screen is now small");
},
unmatch: function() {
this.displayIsLarge = true;
this.displayIsSmall = false;
console.log("the screen is now large");
}
})
);
}
它将在控制台中输出正确的消息(此处为 jsfiddle ),但不会更改displayIsLarge
and的值displayIsSmall
。我在这里想念什么?