zoukankan      html  css  js  c++  java
  • 属性计算之getter


    categories:

    • vue基础
      tags:
    • getter

    属性计算之getter

    <!doctype html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>监听属性</title>
        <style>
            body{
                margin: 20px 0 ;
                padding: 20px 0 ;
            }
            ul{
                list-style: none;
            }
            li{
                margin: 15px 0px;
                padding: 10px 15px;
                border: 1px solid #954;
                border-radius: 3px;
            }
            .active{
                background: #6ff;
    
            }
        </style>
    </head>
    <body>
    <div id="app">
        <audio :src="getCurrentMusicData" autoplay controls></audio>
        <ul>
            <li v-for="(item,index) in musicData" @click="clickHandler(index)" :class="{active: index == currentIndex }">
                <h2>{{item.id}} - - 歌名:{{item.name}}</h2>
                <p>歌手:{{item.author}}</p>
            </li>
    
        </ul>
    </div>
    <script src="./vue.js"></script>
    <script>
        var musicData = [
            {id:1,name:'1于荣光-少林英雄',author:'1于荣光',songSrc:'./static/1于荣光-少林英雄.mp3'},
            {id:2,name:'2于荣光-少林英雄',author:'2于荣光',songSrc:'./static/2于荣光-少林英雄.mp3'},
            {id:3,name:'3于荣光-少林英雄',author:'3于荣光',songSrc:'./static/3于荣光-少林英雄.mp3'},
            {id:4,name:'4于荣光-少林英雄',author:'4于荣光',songSrc:'./static/4于荣光-少林英雄.mp3'},
        ];
        new Vue({
            el:'#app',
            data(){
                return {
                    musicData:musicData,
                    currentIndex:0
                };
            },
            // 实时监控页面数据改变
            computed: {
                // 计算属性默认只有getter
                getCurrentMusicData:function (){
                    console.log(this.musicData[this.currentIndex].songSrc);
                    return this.musicData[this.currentIndex].songSrc;
                }
            },
    
            methods:{
                //监控点击事件,修改当前索引
                clickHandler(index){
                    this.currentIndex = index;
                    // this.musicData[0].songSrc = this.musicData[val].songSrc
    
                }
            }
        })
    </script>
    </body>
    </html>
    
  • 相关阅读:
    java集合归纳
    判断回文数
    29:四则运算计算表达式的值
    getOutString 输出弹出字符串
    两个字符串中不同元素的个数
    字符串各个字符ASCII值加5
    23:一个整数的二进制表示中有多少个1
    Java进程间通信
    转 双重检查锁定与延迟初始化
    Key-Value键值存储原理初识(NOSQL)
  • 原文地址:https://www.cnblogs.com/anyux/p/12202141.html
Copyright © 2011-2022 走看看