[Vuejs]-VueJS – Define components in secondary .js file

0👍

In general your top example looks just right and nothing I would see out of order. The problem though you describe with the addresses probably comes from how you use the UserAddresses.
I would guess you have it nested inside the #app element on the page.
The problem here is, you can’t nest two Vue root instances in each other.

new Vue({...}) // get a Vue rootinstance

What you probably want to do is use a Component. You can use global components for this, and therefor it’s fine to have one global root instance.

window.UserAddresses = Vue.component('user-addresses', {
   data () {
     return {
      addresses: []
     }
   }
   ... // rest of your component code
}

You can get more information here: https://v2.vuejs.org/v2/guide/components.html

Leave a comment