【问题标题】:React Uncaught TypeError: Cannot read property 'replace' of undefinedReact Uncaught TypeError:无法读取未定义的属性“替换”
【发布时间】:2015-04-04 12:40:43
【问题描述】:

我在 React 中将 php 变量转换为 javascript 时遇到问题。

代码如下(内容为西班牙语):

var insertar = "<?php echo $insertar; ?>";

var phpCodeInsertar = React.createClass({

 render : function(){

     if(!insertar){

         return(

             <center id='descripcion-registro-fail'>
                 <h1 id='dr-fail-h1'>Error al registrarte</h1>
                 <ul id='dr-fail-ul'>
                     <li>&middot Comprueba que has escrito bien tus datos.</li>
                     <li>&middot Asegurate de que no estás registrado(en caso contrario no puedes hacerlo de nuevo).</li><br></br>
                     <li id='dr-fail-ul-li'>Si ya has realizado los pasos anteriores y el problema sigue apareciendo, ponte en contacto con el <a id='dr-fail-a'>soporte</a>.</li>
                 </ul>
             </center>

         ); 

     } else {

         return(

         <center id='descripcion-registro'>
             <h1 id='dr-h1'>Gracias por registrarte.</h1>
             <p id='dr-p'>
                 Se ha enviado un correo de confirmación a tu email,<br></br>
                 entra en el enlace que hay en él y sigue las instrucciones para<br></br>
                 confirmar tu cuenta.
             </p>
         </center>

         );

     }

 }

});

我的问题是: 当我呈现页面时,我看到以下消息: Uncaught TypeError: Cannot read property 'replace' of undefined.

我认为 React 检测到“insertar”(一个 bool php 变量)就像 undefined。

如何让 React 正确检测“插入”?

【问题讨论】:

标签: javascript php reactjs


【解决方案1】:

这不是你的 php->javascript 变量的问题

React 类(组件)名称应为以 大写开头的 Camel Cased

所以改变

phpCodeInsertar
为此:
PhpCodeInsertar

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
  • 2016-04-22
  • 1970-01-01
  • 1970-01-01
  • 2015-09-08
  • 2016-05-09
  • 2015-05-29
相关资源
最近更新 更多