Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

关于VUX Panel组件传参问题

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的字段?或者有其他处理方式?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

应该没有其他的处理方式了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...