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
Post a Comment