如何在Ecmascript 6中访问json文件?以下不起作用:
import config from '../config.json'
如果我尝试导入JavaScript文件,这可以正常工作.
以下是我的代码.app.js是根文件,about.js是一个只显示一些文本的文件,而index.js通过使用react-router处理所有路由.我想在app.js中渲染我的about.js. 如果我不在app.js中写"this.props.children",它就不会呈现.
"use strict";
import React from 'react';
import { Link } from 'react-router';
class App extends React.Component {
render() {
console.log(this.props.children)
return(
<div>
<h1>Hello !</h1>
<Link to="about">About</Link>
{this.props.children} **//Is this necessary?**
</div>
)
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
"use strict";
import React from 'react';
class About extends React.Component {
render() {
return(
<div>
<h1>About page!</h1>
</div>
)
}
}
export default About;
Run Code Online (Sandbox Code Playgroud)
import React from 'react';
import { render } from 'react-dom'; …Run Code Online (Sandbox Code Playgroud) 我正在使用JEST和酶。在我的eslint文件中,我在环境下添加了jest作为true。但是由于在全球范围内将其包含在浅表中,因此我得到了一个皮棉错误。错误为-错误'浅'未定义no-undef
setupTests.js
//as we are accessing our application with a http://localhost prefix, we need to update our jest configuration
import { shallow, render, mount, configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
// React 16 Enzyme adapter
configure({ adapter: new Adapter() });
// Make Enzyme functions available in all test files without importing
global.shallow = shallow;
global.render = render;
global.mount = mount;
Run Code Online (Sandbox Code Playgroud)
.eslintrc
{
parser: "babel-eslint",
"extends": ["airbnb"],
"env": {
"browser": true,
"jest": true
},
"rules": {
"max-len": [1, …Run Code Online (Sandbox Code Playgroud) reactjs ×2
babel ×1
ecmascript-6 ×1
enzyme ×1
eslint ×1
import ×1
jestjs ×1
json ×1
react-router ×1