如何为引导Vue表绑定链接:href

问题描述 投票:0回答:1

我是编程新手。我试图弄清楚如何绑定数据以使用存储,vuex和bootstrap-vue表来获取链接:href。我已经花了4天的时间,现在快要死了。请帮助。

books.js(store,vuex)

books: [
    {
      id: 1,
      name: "name 1",
      bookTitle: "book1",
      thumbnail: '../../assets/img/book01.jpeg',
      url: "https://www.google.com",
      regDate: '2019-10'
    },
    {
       id: 2,
      name: "name2",
      bookTitle: "book2",
      thumbnail: "book2",
      url: "http://www.yahoo.com",
      regDate: '2019-10'
    },

BookList.vue

<script>
export default {
  name: "BookList",
  components: {
  },
  computed: {
    fields() {
      return this.$store.state.fields
    },
    books() {
      return this.$store.state.books
    },
    bookUrl() {
      return this.$store.state.books.url
    }
  },
  data() {
    return {
      itemFields: this.$store.state.fields,
      items: this.$store.state.books,
      //url: this.$store.state.books.url
    }
  }

};
</script>
<template>
  <b-container>
    <b-table striped hover :items="items" :fields="itemFields" >
      <template v-slot:cell(thumbnail)="items">
          <img src="" alt="image">
      </template>
      <template v-slot:cell(url)="items">
          <b-link :href="bookUrl" >link</b-link>
      </template>
    </b-table>
  </b-container>
</template>
vue.js data-binding bootstrap-vue
1个回答
0
投票

单元格插槽包含您通常感兴趣的两个属性:

  • [item(当前行,确切地说,是item中的当前items)]
  • [value(单元格-确切地说是value中当前列的item]。]。]
  • 因此,考虑您的数据,在v-slot:cell(url)="{ value, item }"的情况下,value等效于item.url

这些都可以使用:

<template v-slot:cell(url)="{ value }">
  <b-link :href="value">link</b-link>
</template>
<template v-slot:cell(url)="slot">
  <b-link :href="slot.value">{{ slot.item.bookTitle }}</b-link>
</template>
<template v-slot:cell(url)="{ item }">
  <b-link :href="item.url">{{ item.bookTitle }}</b-link>
</template>

工作示例here


[请注意,您的问题包含一些小问题,它们可能会阻止您的代码正常工作(itemFields被引用但未定义,未使用正确的吸气剂,等等。)。有关详细信息,请查看工作示例。并阅读文档!

© www.soinside.com 2019 - 2024. All rights reserved.