如题,方法如下:
export default {
data(){
return {
clientWidth:document.body.clientWidth
}
},
mounted(){
let that = this;
window.onresize =() =>{
return (()=>{
window.clientWidth = document.body.clientWidth;
that.clientWidth = window.clientWidth;
})()
};
},
watch:{
clientWidth(newVal,oldVal){
console.log(newVal);//浏览器窗口变化时,打印宽度。
}
}
}