javascript - How to store and access data on eventBus in VueJS -


basically want able access centralized data setting databus vue instance object, , access , tweak data different components.

i cant seems access data componenets, basic string interpolation not getting rendered dom.

  export const databus = new vue({     data: {       numquotes: 4,       stringvar: 'hellow there'     }   }); 

i tried setting data return of function data(). being data bus actual vue instance don't think correct. (i wrong). following component in import databus , try output data.

  <template>     <div>       <h1>quotes added</h1>       <div id="trackerbar">         <div id="trackerbaractual">             <h2>{{numquotes}}/10</h2>         </div>       </div>     </div>    </template>    <script>     import { databus } '../main.js';      export default{      }   </script> 

i getting following error: property or method "numquotes" not defined on instance referenced during render. make sure declare reactive data properties in data option.

am missing obvious? possible access data way? or have access method?

you're missing part assign data component. try

<script> import { databus } '../main.js';  export default{   data () {     return databus.$data   } } </script> 

you should vuex state management though.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -