vue2

作者: E1FANG | 来源:发表于2019-01-04 16:03 被阅读0次

数据获取

mounted: function () {
                this.common = publicBot;
                // if(this.code) {
                //  axios.post('/home/index/get_code',{code: this.code}).then(function (res) {
                //      console.log(res);
                //     })
                // }
                var _this = this;
                axios.post('/api/index/getHomeInfo', { is_pc: 1 }).then(function (data) {
                    _this.loading = false;
                    if (data.data.code == 1) {
                        var arr = _this.goodsTypeArr;
                        arr = arr.concat(data.data.data.typeArr)
                        _this.goodsTypeArr = arr;
                        _this.secTime = data.data.data.secTime;
                        _this.bannerList = data.data.data.bannerList;
                        // if(_this.timeInfoList.length > 0) {
                        //  _this.handleSecGoods();
                        //  _this.goodsList = _this.timeInfoList[0].goods;
                        //  _this.isBegin = _this.timeInfoList[0].is_buying;
                        // }

                        _this.commentList = data.data.data.recommendGoods;
                        _this.$nextTick(function () {
                            _this.setWidth('.header-nav');
                        })

var this = _this
确保作用域一致

获取数据 axios.post('getHomeInfo')
将数据存储到app.js的data中 _this.secTime = data.data.data.secTime; //数组

渲染 :


<ul class="comment">
                    <router-link :to="{path: '/Home/Index/app/goodsDetail', query: {id: item.id}}" v-for="(item, index) in commentList" :key="index" tag="li">  
                        <img :src="item.recommend_img" alt="" />
                        <!-- <img :src="item" alt="" /> -->
                    </router-link>
</ul>

v-for="(item, index) in commentList" :key="index" tag="li"
循环渲染commentlist中的数据 形式为li

相关文章

网友评论

      本文标题:vue2

      本文链接:https://www.haomeiwen.com/subject/tuhkrqtx.html