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的情况下解决此问题。。。你有什么建议?提前谢谢。您不能直接分配设备的变量。尝试使用动作或突变