0

I have this array:

data() {
    return {
      landingInfo: null,
      slides: [
        {
          title: `this`,
        },
        {
          title: "that",
        },
        {
          title: "those",
        },
      ],
    };
  },

Which is being displayed this way:

 <div
          class="slide"
          v-for="(slide, index) in slides"
          :key="index",
          }"
        >
          <div>
            <h1 class="text-bold">{{ slide.title }}</h1>

          </div>

The problem is that I'm fetching info from and api and once I try to do:

 slides: [
    {
      title: {{ landingInfo.data.subtitle }},
    },
    {
      title: {{ landingInfo.data.subtitle2 }},
 
    },
    {
       title: {{ landingInfo.data.subtitle3 }},
    },
  ],

Everything explodes, I am new in vue using Nuxt.js and I cannot find any solution in how to achieve that. Can someone show me how to include the fetched info inside the array property?

PD: I already tried using "{{thefetchedinfo}}" but it takes it literally that way and displays "{{thefetchedinfo}}"

1
  • 1
    The squiggly braces are only for the template, indicating that their contents should be evaluated as javascript. The rest of the vue instance is a javascript object, which must conform to JS syntax. Squiggly's in this context wouldn't parse. Commented Jan 19, 2021 at 20:56

1 Answer 1

1

The OP doesn't provide much info on the fetch, like when it is performed or what the returned data looks like, but the common pattern goes like this...

// <template> as in the OP, then...

  data() {
    return {
      landingInfo: null,
      slides: [], // empty before the fetch
    };
  },
  mounted () {
    fetchFromTheAPI().then(landingInfo => {
      // More commonly, you'd map over the returned data to form slides,
      // or, trying to match the OP...
      this.slides = [
        { title: landingInfo.data.subtitle },
        { title: landingInfo.data.subtitle2 }, // ... and so on
      ]
    });
  },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.