小编Iva*_*ana的帖子

在 React 的模板文字中插入 html 标签

我在 React 中有带有模板文字的变量:

const weatherForecast = `
  Today in <strong>${this.state.cityName}</strong>
  weather will be with <strong>${today.weather_state_name}</strong>,
  min temperature <strong>${parseInt(today.min_temp)}°C</strong>,
  max temperature <strong>${parseInt(today.max_temp)}°C</strong>,
  and humidity will be <strong>${today.humidity}%</strong>
`;
Run Code Online (Sandbox Code Playgroud)

我想在其中插入 HTML 代码,如您所见,这是 tag 。这可能吗,我该怎么做。我用谷歌搜索,但我找不到答案。

javascript reactjs template-literals

10
推荐指数
1
解决办法
8702
查看次数

Angular CLI 中未显示字体很棒的图标:8.2.2 而是显示正方形

我已经通过 https://www.npmjs.com/package/angular-font-awesome 安装了npm install --save font-awesome angular-font-awesomeFont Awesome

将其链接到 angular.json 中

"styles": [
     "src/styles.css",
     "node_modules/font-awesome/css/font-awesome.min.css"
]
Run Code Online (Sandbox Code Playgroud)

在index.html中我已经链接了该库

<link rel="stylesheet" type="text/css" href="../node_modules/font-awesome/css/font-awesome.min.css">
Run Code Online (Sandbox Code Playgroud)

我的图标 html 代码如下所示:

<i class="fa fa-facebook-f"></i>
Run Code Online (Sandbox Code Playgroud)

并且仍然显示方块而不是图标。

有人可以帮忙吗?

npm font-awesome angular

5
推荐指数
1
解决办法
6953
查看次数

将 props 从父组件转发到子组件

我有 2 个组件列表的帖子,当点击明信片上的链接时,我正在进入帖子。我无法访问子组件中的 props.postDetails。当我控制台记录道具时,我只有 {history: {…}, location: {…}, match: {…}, staticContext: undefined} 没有 props.postDetails。有人可以帮忙吗?

父组件的代码是:

mport {useState, useEffect} from 'react';
import {BrowserRouter as Router, Switch, Route, Link, withRouter} from "react-router-dom";
import logo from "./assets/images/logo.jpg";
import Post from './Post';


const Home = () => {
    const [posts, setPosts] = useState([]);

    useEffect(() => {
        getResults();
    },[]);

    const getResults =() => {
        fetch("https://blog-d8b04-default-rtdb.europe-west1.firebasedatabase.app/posts.json")
            .then(response => response.json())
            .then(data => {setPosts(data)});
    }

    const postsArr = [];
    Object.values(posts).forEach((post, key) => {
        postsArr.push(post);
    });

    return(
        <div>
            <div …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

5
推荐指数
1
解决办法
83
查看次数

为什么 create-react-app 不创建新应用

我使用 npm 在 Node JS 上安装了最新版本,但无法运行 create-react-app。出现以下问题:

Creating a new React app in C:\wamp64\www\bob.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

npm ERR! Unexpected end of JSON input while parsing near '....tgz"}},"2.3.4":{"nam'

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Ivana\AppData\Roaming\npm-cache_logs\2019-02-26T21_21_48_727Z-debug.log

Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.

Deleting generated file... package.json
Deleting bob/ from C:\wamp64\www
Done.
Run Code Online (Sandbox Code Playgroud)

版本:

Node v10.15.1
npm …
Run Code Online (Sandbox Code Playgroud)

reactjs

3
推荐指数
1
解决办法
8349
查看次数

CORS 问题 - 从原点 *** 获取 *** 的访问权限已被 CORS 策略阻止:无“Access-Control-Allow-Origin” - 将请求发送到 Firebase

我遇到 CORS 问题,我正在发送更新数据的 put 请求 - 使用 React 发布到 Firebase:

const submitHandler = e => {
        e.preventDefault();
        const err = validate();
        if(err === false) {
            setFormData(formData)
            const requestOptions = {
                method: 'PUT',
                headers: {'Content-Type': 'application/json'},
                body: JSON.stringify({
                    title: title,
                    url: url,
                    author: author,
                    description: description})
            };
            fetch(`https://blog-d8b04-default-rtdb.europe-west1.firebasedatabase.app/posts/${postName}`, requestOptions)
                .then(response => {response.json(); console.log(response)})
                .then(data => console.log(data));
            setFormData(initialState);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我在控制台中收到此通知错误

Access to fetch at 'https://blog-d8b04-default-rtdb.europe-west1.firebasedatabase.app/posts/-MX1-Df4t59Y3DnyWUzB' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access …
Run Code Online (Sandbox Code Playgroud)

javascript firebase reactjs

3
推荐指数
1
解决办法
1544
查看次数