简体   繁体   English

在 react.js 的锚标签中添加参数

[英]Adding parameter in anchor tag in react.js

I am trying to add a username in my anchor tag's href property.我正在尝试在我的锚标记的href属性中添加用户名。 My Code is,我的代码是,

var Name = React.createClass({

    render: function() {
        return (
            <div>
                <a href="www.example.com/"+ { this.props.username} +"" className="post-title">{this.props.name}</a><br />
            </div>
        );
    }

});

But, I am getting an error saying undefined token + near that href property.但是,我收到一条错误消息,说undefined token +在该 href 属性附近。 I think this is due to I am trying to add it in render method.我认为这是因为我试图在渲染方法中添加它。 So, is there any other approach?那么,还有其他方法吗?

Thank you..谢谢..

Remove the + .删除+ It should be:它应该是:

<a href={"www.example.com/" + this.props.username} ...

另一种方法是:

<a href={`https://www.example.com/${this.props.username1}`}>link</a>

在中使用.map<div> 标签-react.js</div><div id="text_translate"><p> 我真的很感激任何帮助。 所以该项目是一个反应项目。</p><p> 这是我获取<a href="https://i.stack.imgur.com/WelCP.png" rel="nofollow noreferrer">的内容:获取请求</a></p><p>这是我从服务器响应的内容: <a href="https://i.stack.imgur.com/e2QG3.png" rel="nofollow noreferrer">Response from server</a></p><p> 我试了一下 Postman,看看我收到的是什么类型的 json。 这是它返回的内容: <a href="https://i.stack.imgur.com/yg6IE.png" rel="nofollow noreferrer">Postman 测试</a></p><p>我遇到的问题是我无法 map 收到的数据。 一旦输入链接,我只想在首页上以一种很好的方式显示接收到的数据。</p><p> 是否可以将 map 放在 div 标签内? 或者还有另一种方法吗?</p><p> <em><strong>请注意该项目是作为功能组件编写的</strong></em></p></div> - Using .map in <div> tag - react.js

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将组件添加到 React.js - Adding component to React.js 添加 <textarea> 单击React.js上的选项后,在&lt;select&gt;标记内添加一个标记 - Adding <textarea> tag inside a <select> tag after clicking an option on React.js 传递值<select>React.js 中的标签 - Pass value of <select> tag in React.js 使用react.js呈现自定义html标记 - Rendering custom html tag with react.js 如何使用 React.js 访问标签样式 - How to access to tag style with React.js 在中使用.map<div> 标签-react.js</div><div id="text_translate"><p> 我真的很感激任何帮助。 所以该项目是一个反应项目。</p><p> 这是我获取<a href="https://i.stack.imgur.com/WelCP.png" rel="nofollow noreferrer">的内容:获取请求</a></p><p>这是我从服务器响应的内容: <a href="https://i.stack.imgur.com/e2QG3.png" rel="nofollow noreferrer">Response from server</a></p><p> 我试了一下 Postman,看看我收到的是什么类型的 json。 这是它返回的内容: <a href="https://i.stack.imgur.com/yg6IE.png" rel="nofollow noreferrer">Postman 测试</a></p><p>我遇到的问题是我无法 map 收到的数据。 一旦输入链接,我只想在首页上以一种很好的方式显示接收到的数据。</p><p> 是否可以将 map 放在 div 标签内? 或者还有另一种方法吗?</p><p> <em><strong>请注意该项目是作为功能组件编写的</strong></em></p></div> - Using .map in <div> tag - react.js react.js 中的链接标签重定向问题 - link tag redirect issue in react.js 在滚动 React.js 上更新 ID 标签 - Updating an ID tag on scroll React.js 为什么在运行时添加<script>标记不会加载javascript文件? (with react.js) - Why adding a <script> tag at runtime doesn't load the javascript file? (with react.js) React.js onChange<input> 标签挂起 - React.js onChange <input> tag hangs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM