Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

vue的data()中的值能否递归调用

理想的效果是:

标题一??????????????????内容一
标题二??????????????????内容二
标题三??????????????????内容三

实际上的效果是:

标题一??????????????????this.details.c1
标题二??????????????????this.details.c2
标题三??????????????????this.details.c3
<template>
    <div>
        <van-cell-group>
            <van-cell
                v-for="(item, index) in d_list"
                :key="index"
                :title='item.title'
                :value="item.value"/>
        </van-cell-group>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                details: {
                    c1: '内容一',
                    c2: '内容二',
                    c3: '内容三',
                },
                d_list: [
                    {
                        title: '标题一',
                        value: 'this.details.c1',
                    }, {
                        title: '标题二',
                        value: 'this.details.c2',
                    }, {
                        title: '标题三',
                        value: 'this.details.c3',
                    }
                ],
            }
        },
    }
</script>

上面的details{}是从后台传过来的对象,能不能在不改变details{}的情况下,在html中循环输出details{}中的属性值和另外自己定义的title吗


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

亲测有效!

<template>
    <div>
        <van-cell-group>
            <van-cell
                v-for="(item, index) in d_list"
                :key="index"
                :title='item.title'
                :value="details[item.value]"/>
        </van-cell-group>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                details: {
                    c1: '内容一',
                    c2: '内容二',
                    c3: '内容三',
                },
                d_list: [
                    {
                        title: '标题一',
                        value: 'c1',
                    }, {
                        title: '标题二',
                        value: 'c2',
                    }, {
                        title: '标题三',
                        value: 'c3',
                    }
                ],
            }
        },
    }
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...