javascript - How to get the elements traversed by v-for in Vue
淡淡烟草味
淡淡烟草味 2017-05-19 10:15:34
0
1
557
<template>
    <p id="app" class="app">
        <p class="container">
            <p v-for="(item, index) in items">
                {{ item.name }}
            </p>
        </p>
    </p>
</template>

<script>
export default {
    name: 'app',
    data () {
        return {
            items: [
                {
                    name: 'a'
                },
                {
                    name: 'b'
                },
                {
                    name: 'c'
                },
                {
                    name: 'd'
                },
                {
                    name: 'e'
                },
            ]
        }
    },
    methods: {
        getWidth () {
            //  获取遍历 this.items 每个p 元素的宽度  offsetWidth;
            this.items.forEach(el => {
                // .....   怎么做?
            });
        }
    },
    mounted () {
        this.getWidth();
    }
}
</script>



As long as we can get the traversed target element, everything is easy to say. Can't seem to do it?

淡淡烟草味
淡淡烟草味

reply all(1)
过去多啦不再A梦

mounted there? Try using this.$nextTick(()=>{this.getWidth()})?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template