[Vuejs]-Using the Axios CDN to display in Vue Template

0👍

It’s unclear if ID is a property or a route parameter. I think you’re using a route parameter here. If so, and you’re not passing it into the component directly, then I think you can safely drop it and replace it with a computed property that will return the ID. Then simply add a method that will perform your axios request. And call that request in the mounted method of your component.

My thoughts are:

const Home = { 
  template: `

  <div class="user">
    <h2>user {{ id }}</h2>
    bet
  </div>

  `,
  mounted: function() {
    this.myRequest()
  }, 
  computed: {
    id: {
      get: function() {
        return this.$route.params.id
      }
    }
  },
  methods: {
    myRequest() {
      axios.get('/path/to/my/request', { params: { id: id }})
        .then(response => {
          console.log(response)
        }).catch(error => {
          console.log(response)
        })
    }
  }
}

Leave a comment