直接上代碼
<template>
<div id="app">
<div :style="{width: `${screenWidth}px`}">
<router-view/>
</div>
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
screenWidth: document.body.clientWidth
}
},
mounted () {
const that = this
window.onresize = () => {
return (() => {
window.screenWidth = document.body.clientWidth
that.screenWidth = window.screenWidth
})()
}
},
watch: {
screenWidth (val) {
this.screenWidth = val
}
}
}
</script>