Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将数据从serverPrefetch()提取到mounted()中_Javascript_Vue.js_Vuejs2_Server Side Rendering - Fatal编程技术网

Javascript 将数据从serverPrefetch()提取到mounted()中

Javascript 将数据从serverPrefetch()提取到mounted()中,javascript,vue.js,vuejs2,server-side-rendering,Javascript,Vue.js,Vuejs2,Server Side Rendering,按议题提问: 我想从服务器端接受数据,以便在客户端使用它 export default { // ... serverPrefetch () { this.$store.device = this.$vnode.ssrContext.device console.log(this.$store.device) // desktop }, mounted () { console.log(this.$store.d

按议题提问:

我想从服务器端接受数据,以便在客户端使用它

export default {
    // ...
    serverPrefetch () {
        this.$store.device = this.$vnode.ssrContext.device

        console.log(this.$store.device) // desktop
    },

    mounted () {
        console.log(this.$store.device) // undefined
    }
    // ...
}

尝试使用商店,但不起作用。请告诉我如何解决这个问题。

为什么不直接使用nuxt@ifaruki出于某种原因,您需要在不使用Nuxt的情况下解决此问题。。。你有什么建议?提前谢谢。您不能直接分配设备的变量。尝试使用动作或突变