我无法弄清楚为什么我的组件的 Render 函数中的替换函数出现错误。
类型错误:无法读取未定义的属性“替换”
我只是想从services.serviceImage替换字符串值并替换像"react-site/public/",""这样的字符串,就像你通常对任何字符串所做的一样,我做了一些测试,我可以确认返回的值是一个字符串,我做了一些其他的字符串替换,它起作用了,但在这种情况下,有些东西不起作用......为什么?
我已经尝试过作为正则表达式方法,但没有运气:
imgUrl = imgUrl.replace("/react\-site\/public/g", "");
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我的节点服务器也不接受 doc.serviceImage 响应的替换方法!!!
我在这里做错了什么......?
我的完整代码:
import React, {Component} from 'react';
import axios from 'axios';
//import { Link } from "react-router-dom";
import './catalogue.scss';
class ServicesPage extends Component {
state = {
services: [],
loading: false
}
componentDidMount(){
this.setState({
loading: true
});
axios.get('/services')
.then(response => {
console.log(response);
this.setState({
services: response.data.services,
loading: false
});
})
.catch( error => {
console.log(error);
});
document.title = "Pain Relief and Massage Services - …Run Code Online (Sandbox Code Playgroud)