vue中动态修改css其中一个属性值

我就是我 2022-03-30 03:41 444阅读 0赞
  1. <template>
  2. <!--此div的高度取屏幕可视区域的高度-->
  3. <div class="hello" :style="{'height':getClientHeight}">
  4. <h5>{
  5. { msg }}</h5>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. msg: "Welcome to Your Vue.js App",
  13. };
  14. },
  15. computed: {
  16. getClientHeight:function () {
  17. //屏幕可视区域的高度
  18. let clientHeight = document.documentElement.clientHeight + "px"
  19. console.log("clientHeight 1=="+clientHeight)
  20. //窗口可视区域发生变化的时候执行
  21. window.onresize = () => {
  22. clientHeight = document.documentElement.clientHeight + "px"
  23. console.log("clientHeight changed2=="+clientHeight)
  24. return clientHeight
  25. }
  26. console.log("clientHeight 3=="+clientHeight)
  27. return clientHeight
  28. }
  29. }
  30. };
  31. </script>
  32. <!-- Add "scoped" attribute to limit CSS to this component only -->
  33. <style scoped>
  34. .hello{
  35. width: 100%;
  36. background-color: #42b983;
  37. }
  38. </style>

发表评论

表情:
评论列表 (有 0 条评论,444人围观)

还没有评论,来说两句吧...

相关阅读