1

I defined some data in a instance, but when I use the data, I receive this message:

Property or method "url" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

This is where the data is located:

Vue.component('app-dashboard', require('./components/AppDashboard.vue'));
Vue.component('header-top', require('./components/Header.vue'));
Vue.component('navbox', require('./components/Navbox.vue'));
Vue.component(Vodal.name, Vodal);

const app = new Vue({
    el: '#app',
    data: {
      url: {
        dashboard: laroute.route('dashboard'),
        request: laroute.route('requests.get'),
        send: laroute.route('requests.send'),
        history: laroute.route('history'),
        userAll: laroute.route('users.all')
      }
    }
});

This is how I use the data in my component:

// Header.vue
    <li class="nav-item active">
          <a class="nav-link" :href="url.dashboard">Dashboard <span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" :href="url.request">File Request</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" :href="url.send">Send Files</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" :href="url.history">History</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" :href="url.userAll">User Management</a>
        </li>
1
  • Use Vuex. Its far better than props, cleaner, more readable. Commented Jul 25, 2017 at 20:01

1 Answer 1

2

In Vue, children do not have access to their parent's data directly, you need to pass it down as a property.

In your Header.vue component you should define a property called url

export default {
  props:["url"],
  ...
}

and pass the value in the parent's template.

<header-top :url="url"></header-top>

The Vue documentation is excellent. You should read through component composition.

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.