<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>
本文介绍了一个使用Vue.js实现的响应式布局方案,通过监听屏幕宽度的变化调整页面元素的宽度,确保了不同设备上的一致视觉体验。
2153

被折叠的 条评论
为什么被折叠?



