Home>

I want to use the string passed from the parent component as a variable in script.
When console.log (this.title) was done, it was clearly displayed as News, and typeof was also string.
However, if it is db.collection (this.title) as it is, data cannot be obtained.
Thank you.
firestore ref

firebase 5.4.1


Parent

<Data title = "News" />


Direct assignment worked.
Data.vue

<script>
export default {
  name: "Data",
  props: {
    title: String
  },
  data () {
    console.log (this.title);
    var data = [];
    var ids = [];
    var str = "news";
    db
      .collection (str)<---------------------- here
      .get ()
      .then (function (querySnapshot) {
        querySnapshot.forEach (function (doc) {
          // doc.data () is never undefined for query doc snapshots
          console.log (doc.id, "=>", doc.data ());
        });
      });return {
      list: data
    };
  }
};
</script>
  • Answer # 1

    title ='News'
    Uppercase m (-) m

Related articles