gpt4 book ai didi

javascript - 如何在模板中使用组件的数据对象的值?

转载 作者:行者123 更新时间:2023-12-01 01:13:28 25 4
gpt4 key购买 nike

我是 Vue Js 新手,我被困在这里......

模板未加载。我不知道我犯了什么错误!

收到以下错误消息:

[Vue warn]: Error in render: "TypeError: Cannot read property 'undefined' of undefined"

<template>
<div v-if= "this.config.ignoreheader == false">
<div v-if= "this.config.emptyinput == true">
<input type="text" :id = "this.config.id ? this.config.id : ''" data-auto-input :placeholder = "this.config.placeholder" class='siq-input' autofocus>
<p class='italic-text' dropdown-input></p>
</div>
<div v-else>
<div class="drpdwn-input" :class= '[isAutoComplete() ? "autofill" : "", this.config.noShadow ? "noShadow" : ""]' data-header>
<em v-if= "this.config.searchicon" class="fsiq-search"></em>
<em v-if= "this.config.showarr" class="fsiq-darrow"></em>
<input type="text" :id = "this.config.id ? this.config.id : ''" data-auto-input :placeholder = "this.config.placeholder" :value = "this.config.selectedkey">
<div class="drpdwn-label" dropdown-label>{{this.config.data[this.config.selected] || 'Choose a list'}}</div>
</div>
</div>
</div>
</template>
<script>

export default {
name: "Atom",

props: {
dataObj: {
type: Array,
required: true,
default: () => []
},
options:{

}
},

data: function() {
return {
config: {
type : "autocomplete",//No I18N
searchicon: true,
showarrow : true,
emptyinput: false,
placeholder : "Search",//No I18N
noMatchesText : "Search Not Found!",//No I18N
ignoreheader : false,
dataonly : true,
selectedkey : ''
}
};
},
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

最佳答案

没有data在你的config对象也没有 selected在您的config上对象。

这是导致错误的行

<div class="drpdwn-label" dropdown-label>{{this.config.data[this.config.selected] || 'Choose a list'}}</div>

你可能想做这样的事情:

{{ (this.config.data && this.config.selected) ? this.config.data[this.config.selected] : 'Choose a list'}}

关于javascript - 如何在模板中使用组件的数据对象的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54969863/

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