1.style样式的动态绑定
    2.生命周期
    3.事件监听

    1. <template>
    2. <div class="about">
    3. <h1 class="nav" :style="{opacity:opacity}">This is an about page</h1>
    4. </div>
    5. </template>
    6. <script>
    7. export default {
    8. data(){
    9. return {
    10. opacity:0
    11. }
    12. },
    13. mounted(){
    14. window.addEventListener("scroll",this.handle)
    15. },
    16. methods:{
    17. handle(){
    18. var height = document.documentElement.scrollTop;
    19. /* 到达300完全显示 */
    20. var opacity = height/300;
    21. if(opacity>1){
    22. opacity = 1;
    23. }
    24. console.log(opacity)
    25. this.opacity = opacity;
    26. }
    27. },
    28. destroyed(){
    29. window.removeEventListener("scroll",this.handle)
    30. }
    31. }
    32. </script>
    33. <style scoped>
    34. .nav{
    35. position: fixed;
    36. top:0;
    37. left:0;
    38. width:100%;
    39. height: 40px;
    40. background: red;
    41. z-index: -1;
    42. }
    43. </style>