【发布时间】:2020-01-22 04:27:20
【问题描述】:
来自 React 开发环境,目前我正在挑战自己学习一些 Vue。但是,在组件之间传递数据作为道具时,我遇到了一些问题。
我的目标是将列表中的字符串显示为
元素,稍后我将使用过渡动画。为此,我使用 Vue Cli 创建了一个 Vue 项目,其他库仅包括 Bootstrap 和 Router。
我就是不能让它工作......
所以我有一个 main.js 包含我的路径和:
new Vue({
router,
data: {
listOfStrings: ['test1 test1', 'test2', 'test3']
},
render: h => h(App),
}).$mount('#app')
我还有一个 Home.vue,其中包含一个带有大图像的区域,我想在其中放置列表中的句子。
<template>
<div class="homelander">
<div class="container">
<TextHome/>
</div>
</div>
</template>
<script>
import TextHome from '../components/TextHome.vue'
export default {
name: 'Home',
components: {
TextHome
}
</script>
}
最后,我有一个 TextHome 组件,实际上我想通过能够将包含字符串的列表作为道具传递来重用它。
TextHome.vue
<div v-for="item in listOfStrings" v-bind:key="item">
<p>{{item}}</p>
</div>
不管我尝试什么,列表是未定义的,或者我得到“属性或方法“listOfStrings”未在实例上定义但在渲染期间引用。”,甚至由于缺少键而导致错误字符串中的每个字符...所以,是的..我很困惑...如果有人能解释一下这个烂摊子,我将不胜感激。
【问题讨论】:
标签: vue.js vuejs2 frontend vue-component