首先要保证你的div要在<template></template>里面,然后可以这样写 登录后复制 <div class="sub-window-wrapper" :style="dynamicStyles"></div> 1. 下面是呼应 登录后复制 computed: { dynamicStyles() { let browserWidth = window.innerWidth; let halfVideoWidth = this.videoWidth/2; let videoMarginLeft = (browserWidth-halfVideoWidth)/2; console.log("videoMarginLeft is:" + videoMarginLeft) return { width: halfVideoWidth + "px", // marginLeft: "560px", marginLeft: videoMarginLeft + "px", zIndex: 1, position: "relative", }; }, }, 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16. 原创作者: u_9411799 转载于: https://blog.51cto.com/u_9411799/11411514