在变量或数据属性跟踪窗口大小的情况下,是否可以使用react 式窗口宽度
例如
computed:{
smallScreen(){
if(window.innerWidth < 720){
this.$set(this.screen_size, "width", window.innerWidth)
return true
}
return false
}
在变量或数据属性跟踪窗口大小的情况下,是否可以使用react 式窗口宽度
例如
computed:{
smallScreen(){
if(window.innerWidth < 720){
this.$set(this.screen_size, "width", window.innerWidth)
return true
}
return false
}
我不认为有办法做到这一点,除非你在windows 上安装一个监听器.
试试这样:
<template>
<p>Resize me! Current width is: {{ windowWidth }}</p>
</template
<script>
export default {
data() {
return {
windowWidth: window.innerWidth
}
},
mounted() {
window.onresize = () => {
this.windowWidth = window.innerWidth
}
}
}
</script>
希望有帮助!