Panel.vue代码如下
<template v-if="type === '1'">
<a :href="getUrl(item.url)" v-for="item in list" @click.prevent="onItemClick(item)" class="weui-media-box weui-media-box_appmsg">
<div class="weui-media-box__hd" v-if="item.src">
<img class="weui-media-box__thumb" :src="item.src" alt="">
</div>
<div class="weui-media-box__bd">
<h4 class="weui-media-box__title">{{item.title}}</h4>
<p class="weui-media-box__desc">{{item.desc}}</p>
</div>
</a>
</template>
script代码如下:
<script>
import { go, getUrl } from '../../libs/router'
export default {
props: {
header: String,
footer: Object,
list: Array,
type: {
type: String,
default: '1'
}
},
methods: {
getUrl (url) {
return getUrl(url, this.$router)
},
onClickFooter () {
this.$emit('on-click-footer')
go(this.footer.url, this.$router)
},
onClickHeader () {
this.$emit('on-click-header')
},
onItemClick (item) {
this.$emit('on-click-item', item)
go(item.url, this.$router)
}
}
}
</script>
服务器返回的数据如下:
[
{
'title':"日用品",
'list':[
{
src: 'http://yanxuan.nosdn.127.net/715899c65c023bb4973fb0466a5b79d6.png?imageView&quality=95&thumbnail=245x245',
title: '泡泡纱可水洗夏凉被',
desc: '全棉泡泡纱,柔软亲肤',
desc2: '¥229',
url:"/goods/goodsdetail/1"
},{
src: 'http://yanxuan.nosdn.127.net/715899c65c023bb4973fb0466a5b79d6.png?imageView&quality=95&thumbnail=245x245',
title: '泡泡纱可水洗夏凉被',
desc: '全棉泡泡纱,柔软亲肤',
desc2: '¥229',
},]
},
]
并没有URL字段
问题是:
是不是需要我从服务端拿到数据之后,循环处理,给每个item生成一个url的字段?或者有其他处理方式?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…