dsjq6977 2016-12-31 01:13
浏览 111

初始vue.js vuex存储状态的服务器端计算

I am working on a project for which I have an API service and webclient service (Hosted on google appengine, just for information). The webapp/webclient is served by a golang server, which will take requests, make appropriate API calls and compile HTML template with data from the API call In order to initiate the page with some information instead of waiting for the app itself to make API calls, which could be less SEO friendly.

As a javascript Rendering engine/framework I am using vue.js, and in order to share state between components and to have a single source of truth, I am trying to use vuex ... The thing gets a little bit dirty because I am injecting some Javascript in the response served by the webserver, containing a dynamic vuex.Store.state ... The initial state is inserted in the HTML response, which later imports an external Js file (the app) which would call this global Store, and insert it in the root Vue instance and every of its children.

The issue is that when trying to access the store.state via this.$store.state I receive

TypeError: undefined is not an object (evaluating 'this.$store.state') 

Any idea? Is it possible to initiate the store in a HTML file, use the store in a later imported external file to inject its content? In the external JS I am able to call the global Store and log it in the console, so this object seems to be global as expected.

when starting the root Vue instance and passing the store in the options, seems to be a problem because I get an error when trying to call this.$store.state in child Vue.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题