小编Nik*_*dia的帖子

如何在ecmascript 6中导入json文件?

如何在Ecmascript 6中访问json文件?以下不起作用:

import config from '../config.json'

如果我尝试导入JavaScript文件,这可以正常工作.

import json ecmascript-6

128
推荐指数
11
解决办法
12万
查看次数

React 0.14 - 使用react-router

以下是我的代码.app.js是根文件,about.js是一个只显示一些文本的文件,而index.js通过使用react-router处理所有路由.我想在app.js中渲染我的about.js. 如果我不在app.js中写"this.props.children",它就不会呈现.

App.js - 呈现其中所有子组件的根文件.

"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)

About.js

"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)

Index.js - 处理路由的文件

import React from 'react';
import { render } from 'react-dom'; …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router

15
推荐指数
1
解决办法
859
查看次数

解决linter错误-未定义“浅” no-undef

我正在使用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)

babel reactjs eslint jestjs enzyme

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

标签 统计

reactjs ×2

babel ×1

ecmascript-6 ×1

enzyme ×1

eslint ×1

import ×1

jestjs ×1

json ×1

react-router ×1