我是个编程新手。我正在尝试弄清楚如何绑定数据来获得链接:href work使用store、vuex和bootstrap-vue table。我已经为此花了4天了,现在我要死了。请帮帮忙。
Books.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>
发布于 2019-10-20 23:57:04
单元格插槽包含您通常感兴趣的两个属性:
item (当前行,准确地说,是items)value中的当前item )(单元格,或者,准确地说,是item).中当前列的value
因此,考虑到您的数据,在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但没有定义,没有使用正确的getter,等等)。有关详细信息,请查看工作示例。
并阅读文档!
https://stackoverflow.com/questions/58474034
复制相似问题