0

我正在尝试通过 URL 将变量传递给 ReactVR。

当我从组件中 console.log 'window.location.pathname' 时,它会记录' http://localhost:3001/dddfe37b-926a-4adf-b40c-fda47bf3cf8b ',

即使我的网址是“ http://localhost:3001/vr ”,并且预期的输出是“/vr”。

我会就如何将变量从 express.js 路由传递到 ReactVR 提出任何建议。

代码是 react-vr init 的样板,除了“state”和“componentDidMount()”

import React from 'react';
import {
  AppRegistry,
  asset,
  Pano,
  Text,
  View,
} from 'react-vr';
import io from 'socket.io-client';

export default class view_react_vr extends React.Component {
  state = {
room: window.location.pathname
  }

  render() {
    return (
      <View>
        <Pano source={asset('chess-world.jpg')}/>
        <Text
          style={{
            backgroundColor: '#777879',
            fontSize: 0.8,
            fontWeight: '400',
            layoutOrigin: [0.5, 0.5],
            paddingLeft: 0.2,
            paddingRight: 0.2,
            textAlign: 'center',
            textAlignVertical: 'center',
            transform: [{translate: [0, 0, -3]}],
          }}>
          hello
        </Text>
      </View>
    )
  }

  componentDidMount() {
    let socket = io('http://localhost:3001/');

    // socket.emit('newRoom', this.state.room);
    socket.emit('updateState', this.state);
    socket.on('updateState', nextState => {
      console.log(nextState);
    });
  }

};

AppRegistry.registerComponent('view_react_vr', () => view_react_vr);
4

0 回答 0