首先要保证你的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.