[Vuejs]-Vue – access JSON data in method

3👍

You are currently using the Composition API (setup function) alongside the options-based API (methods object). Although it is possible, it is not recommended (take a look at their motivation). Your methods should stand in the setup function:

setup () {
  const page = usePage()
  page.images.forEach((item) => {
    console.log(item)
  })
  return {
    page,
  }
},

Of course, you could still modularize this code using functions.

setup() {
  // ...
  const getOrientations = () => {
    page.images.forEach((item) => {
      console.log(item)
    })
  }

  // And make it available to your template
  return {
    // ...
    getOrientations
  }
}

Leave a comment