javascript - vue v-for資料無法取到
淡淡烟草味
淡淡烟草味 2017-06-12 09:31:04
0
4
739

v-for 迴圈是使用queryselectorall無法取到資料

<p class="content clearfix">
            <ul>
                <li v-for='item in items' :key=item>
                    <p>
                        <img :src="item.picList[0].imgurl"  alt="item.t_name">
                        <p>{{item.title}}</p>
                        <span>{{item.datanum}}张</span>
                    </p>
                </li>
            </ul>
        </p>
created () {
            this.getData();
        },
    methods: {
            getData () {
                let _this = this;
                this.loading = true;
                this.$http.get('web/app/query.do', {
                    params: {
                        'key': '88845608c16c76ef9f4a56b12e3f238be',
                        'pageSize': '10',
                        'a_no': '001',
                        'classify': '01'
                    }
                }).then((res) => {
                    _this.items = res.body.result;
                    _this.waterfull();
                    console.log(_this.items);
                }, (err) => {
                    console.log(err);
                });
            },
            waterfull () {
                var items = document.querySelector('.content');
                var boxes = items.querySelectorAll('li');
                console.log(items);
                // var totalWidth = items.style.width;
                console.log(boxes);
                }

#
淡淡烟草味
淡淡烟草味

全部回覆(4)
某草草

了解實例的生命週期,在created階段,dom還沒被渲染出來

迷茫

樓上說的對,你可以在渲染的時候這樣寫

_this.waterfull();
setTiomout(function(){
    _this.items = res.body.result;
});

這樣應該就可以的,如果不行的話,試著在setTimeout裡填個時間,毫秒級的就行

Peter_Zhu

確實是生命週期的問題,但我比較納悶的是,既然用了vue,為什麼還要透過Dom的方式來取呢?

刘奇

可以使用ref直接綁定dom元素,然後用$refs來操作比較好。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!