gpt4 book ai didi

vuejs2 - "Property or method is not defined on the instance but referenced during render"

转载 作者:行者123 更新时间:2023-12-04 14:39:09 24 4
gpt4 key购买 nike

我需要在item.title之外显示<v-carousel>,但是出现以下错误消息:

[Vue warn]: Property or method "item" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.



我检查了Stackoverflow搜索的结果,但我真的很难理解。如果有人可以通过这个例子向我解释一下,我将不胜感激。
这是我的代码:
<v-carousel>
<v-carousel-item v-for="(item,i) in items" v-bind:src="item.src" :key="i">
</v-carousel-item>
</v-carousel>

<h1>TITLE: {{ item.title }}</h1>

<script>
export default {
data () {
return {
items: [
{
src: '/static/a.jpg',
title: 'A',
text: 'texta'
},
{
src: '/static/b.jpg',
title: 'B',
text: 'textb'
}
{
}
}
}
</script>

这是我需要存档的内容:

一旦图像更改为下一个图像-范围外的 文本也应更改。我试图检查范围之外的item数组的值,但是它不起作用:<h1 v-if="(item,i) === 1">Lion</h1> <h1 v-if="(item,i) === 2">Ape</h1>如何访问范围之外的当前轮播项目的值?

最佳答案

您需要在v-model组件上添加v-carousel:

<v-carousel v-model="carousel">
<v-carousel-item
v-for="(item,i) in items"
v-bind:src="item.src"
:key="i"
></v-carousel-item>
</v-carousel>
//then set title like this:
<h1>TITLE: {{ items[carousel].title }}</h1>

并将 carousel变量添加到 data
data () {
return {
carousel: 0, //like this
items: [
...

关于vuejs2 - "Property or method is not defined on the instance but referenced during render",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48244586/

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