【发布时间】:2026-02-05 10:00:02
【问题描述】:
我无法让数据显示在我的 Vue 组件中。我正在使用 Vueify,我正在尝试从 listings.vue 组件加载列表数组,但我不断收到错误消息。另外,我不明白如何通过computed 方法提取数据。任何帮助将不胜感激。
这是我在控制台中遇到的错误:
[Vue warn]: The "data" option should be a function that returns a per-instance value in component definitions.
[Vue warn]: $mount() should be called only once.
这是我的 app.vue
// app.vue
<style>
.red {
color: #f00;
}
</style>
<template>
<div class="container">
<div class="listings" v-component="listings" v-repeat="listing"></div>
</div>
</template>
<script>
module.exports = {
replace: true,
el: '#app',
components: {
'listings': require('./components/listings.vue')
}
}
</script>
这是我的 Listings.vue 组件
<style>
.red {
color: #f00;
}
</style>
<template>
<div class="listing">{{title}} <br> {{description}}</div>
</template>
<script>
module.exports = {
data: {
listing: [
{
title: 'Listing title number one',
description: 'Description 1'
},
{
title: 'Listing title number two',
description: 'Description 2'
}
]
},
// computed: {
// get: function () {
// var request = require('superagent');
// request
// .get('/post')
// .end(function (res) {
// // Return this to the data object above
// // return res.title + res.description (for each one)
// });
// }
// }
}
</script>
【问题讨论】:
标签: javascript arrays node.js vue.js