vue标签内循环数据逗号分隔


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue标签内循环数据逗号分隔</title>
    <script src="http://unpkg.com/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <template>
            <span v-for="(item,index) in nameData">
                {{ index == nameData.length-1 && item.name || (item.name + ',') }}
            </span>
        </template>
    </div>

    <script>
        var Main = {
            data() {
                return {
                    nameData: [
                        {
                            name: '张三'
                        },
                        {
                            name: '李四'
                        },
                        {
                            name: '王五'
                        },
                        {
                            name: '赵六'
                        }
                    ]
                };
            }
        }
        var Ctor = Vue.extend(Main)
        new Ctor().$mount('#app')
    </script>
</body>

</html>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM