1. 1.style样式的动态绑定
    2. 2.生命周期函数
    3. 3.事件监听
    1. <template>
    2. <div class="about">
    3. <h1 class="nav" :style="{opacity:opacity}">This is an about page</h1>
    4. {{this.$store.state.city}}
    5. </div>
    6. </template>
    7. <script>
    8. export default {
    9. data(){
    10. return {
    11. opacity:0.2
    12. }
    13. },
    14. mounted(){
    15. window.addEventListener("scroll",this.handle)
    16. },
    17. methods: {
    18. handle(){
    19. var height=document.documentElement.scrollTop;
    20. /* 达到300完全显示 */
    21. var opacity=height/300;
    22. if(opacity>1){
    23. opacity=1
    24. }
    25. this.opacity=opacity;
    26. console.log(height)
    27. }
    28. },
    29. destroyed(){
    30. window.removeEventListener("scroll",this.handle)
    31. }
    32. }
    33. </script>
    34. <style scoped>
    35. .nav{
    36. width: 100%;
    37. height:40px ;
    38. background: red;
    39. position: fixed;
    40. top: 0;
    41. left: 0;
    42. }
    43. h1{
    44. margin: 0;
    45. }
    46. </style>