代码之家  ›  专栏  ›  技术社区  ›  simo

使用修饰时,对象(…)不是函数

  •  0
  • simo  · 技术社区  · 7 年前

    我试图通过使用 decorate mobx-react 但是,我得到错误:

    Uncaught TypeError: Object(...) is not a function
        at Object../src/vrp-ui/Button.js (Button.js:32)
        at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
        at Object../src/map/StudentsMap.js (logo.svg:1)
        at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
        at Object../src/App.js (App.css?9a66:26)
        at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
        at Object../src/index.js (index.css?f255:26)
        at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
        at Object.0 (Button.js:32)
        at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
    

    以下是我的实现:

    import React, { Component } from 'react'
    import {Button} from 'semantic-ui-react'
    import axios from 'axios'
    
    import { decorate, observable } from "mobx"
    
    class componentName extends Component {
    
        //@observable vrp_solution = {};
    
        constructor () {
            super()
            this.state = {
              solution: []
            }
            this.handleClick = this.handleClick.bind(this)
          }
    
          handleClick () {
            axios.post('http://localhost:8000/vrp/')
              .then(response => {
                vrp_solution= "!";
                console.log(response)})
          }
    
    
      render() {
        return (
          <Button onClick={this.handleClick}>
            Calculate Best Routes!
          </Button>
        )
      }
    }
    
    export default decorate(componentName,{vrp_solution: observable });
    
    
    #Error is here: 
    
    export default decorate(componentName,{vrp_solution: observable });
    

    如果我移除 装饰 错误消失了。 知道吗?

    1 回复  |  直到 7 年前
        1
  •  0
  •   supra28    7 年前

    装饰性和可观察性来自MOBX而非MOBX反应, 尝试,

    从“mobx”导入装饰,可观察

    你的按钮也应该是

    <Button>
       Calculate Best Routes!
    </Button>