Подтвердить что ты не робот

Как отображать данные через компоненты с помощью Vue.js(используя Vueify)?

У меня возникают проблемы с отображением данных в моих компонентах 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>

Вот мой компонент listing.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>
4b9b3361

Ответ 1

Первое предупреждение означает, что когда вы определяете компонент, параметр data должен выглядеть следующим образом:

module.exports = {
  data: function () {
    return {
      listing: [
          {
            title: 'Listing title number one',
            description: 'Description 1'
          },
          {
            title: 'Listing title number two',
            description: 'Description 2'
          }
        ]
     }
   }
}

Кроме того, не ставьте запросы ajax внутри вычисленных свойств, так как вычисляемые геттеры получают оценку каждый раз, когда вы обращаетесь к этому значению.