首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在b-table - BootstrapVue的v-slot:cell()模板中获取项值

如何在b-table - BootstrapVue的v-slot:cell()模板中获取项值
EN

Stack Overflow用户
提问于 2019-10-20 22:32:16
回答 1查看 10.6K关注 0票数 6

我是个编程新手。我正在尝试弄清楚如何绑定数据来获得链接:href work使用store、vuex和bootstrap-vue table。我已经为此花了4天了,现在我要死了。请帮帮忙。

Books.js(商店、vuex)

代码语言:javascript
复制
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

代码语言:javascript
复制
<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>
代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-20 23:57:04

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

  • item (当前行,准确地说,是items)
  • value中的当前item )(单元格,或者,准确地说,是item).

中当前列的value

因此,考虑到您的数据,在v-slot:cell(url)="{ value, item }"的情况下,value等同于item.url

其中的任何一个都可以工作:

代码语言:javascript
复制
<template v-slot:cell(url)="{ value }">
  <b-link :href="value">link</b-link>
</template>
代码语言:javascript
复制
<template v-slot:cell(url)="slot">
  <b-link :href="slot.value">{{ slot.item.bookTitle }}</b-link>
</template>
代码语言:javascript
复制
<template v-slot:cell(url)="{ item }">
  <b-link :href="item.url">{{ item.bookTitle }}</b-link>
</template>

工作示例here

注你的问题包含一些小问题,这些问题可能会阻止你的代码工作(引用了itemFields但没有定义,没有使用正确的getter,等等)。有关详细信息,请查看工作示例。

并阅读文档!

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58474034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档