Welcome to OStack Knowledge Sharing 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 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...