vue.js - How to use Vue instance data in components? -


i defined data in instance, when use data, receive message:

property or method "url" not defined on instance referenced during render. make sure declare reactive data properties in data option.

this data 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 how use data in 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> 

in vue, children not have access parent's data directly, need pass down property.

in header.vue component should define property called url

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

and pass value in parent's template.

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

the vue documentation excellent. should read through component composition.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -