mobx装饰器报错完整解决方案

1.mobx装饰器报错完整解决方案_第1张图片
解析错误:不允许在装饰器和类之间使用export关键字。请使用' export @dec class '代替。

(错误)
@connect('aaa')
export default class AppView extends React.Component{
    render(){
       //....
    }
  }
(正确)
@connect('aaa')
 class AppView extends React.Component{
    render(){
       //....
    }
  }
export default AppView 

如果还不行,由于MobX Decorators在Create-React-App v2中使用报错,因此需要配置(此配置相当于修改webpack配置的另一种方式)
参考https://blog.csdn.net/wangwei...

mobx装饰器报错完整解决方案_第2张图片

2.使用inject报错
首先确保用包裹了路由页

import { Provider } from 'mobx-react'  
import store from './store'
function App() {  
    return (
         
            
                
                
            
         
     );  
}
         

其次@inject('store')中的注入名称与的配置项名称一致,即都是store
如果@inject('appStore'),与中的store不一致,就会报错
image.png

或者将 改为,那么@inject('mobx的实例名称appStore')

// mobx.js文件
class AppStore {}
const appStore = new AppStore()  
const store = { appStore }  
export default store

//App.js文件

    
        
        
    
 
 
// login.js文件
 @inject('appStore')
 

你可能感兴趣的:(mobx,react.js)