gpt4 book ai didi

vue.js - 如何在 v-slot :cell() template of b-table - BootstrapVue 中获取项目值

转载 作者:行者123 更新时间:2023-12-04 22:48:04 26 4
gpt4 key购买 nike

我是一个非常新的编程。我试图弄清楚如何绑定(bind)数据以获取链接:href 使用 store、vuex 和 bootstrap-vue 表工作。我为此花了4天时间,现在我快死了。请帮忙。

book.js(商店,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>

最佳答案

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

  • 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 被引用但未定义,未使用正确的 setter/getter 等...)。有关详细信息,请查看工作示例。
    并阅读文档!

    关于vue.js - 如何在 v-slot :cell() template of b-table - BootstrapVue 中获取项目值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58474034/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com