SmallComfort / react-vue

Run Vue in React and React Native
MIT License
1.23k stars 62 forks source link

react native 下报错 #2

Closed zhuchaoming closed 7 years ago

zhuchaoming commented 7 years ago

npm 安装 react-vue,但最高版本是0.0.3: npm install --save react-vue

运行报错:

error: bundling: SyntaxError: E:/develop/code/react-native/cpd/src/test1.js: Unexpected token (17:0) 15 | }); 16 |

17 | @observer | ^ 18 | export default class Demo extends Component { 19 | render () { 20 | return

{store.count}

; at Parser.pp$5.raise (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:4454:13) at Parser.pp.unexpected (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:1761:8) at Parser.pp$1.parseDecorator (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:1939:10) at Parser.pp$1.parseDecorators (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:1924:26) at Parser.pp$1.parseStatement (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:1818:10) at Parser.parseStatement (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:5860:22) at Parser.pp$1.parseBlockBody (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:2268:21) at Parser.pp$1.parseTopLevel (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:1778:8) at Parser.parse (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:1673:17) at parse (E:\develop\code\react-native\cpd\node_modules\babylon\lib\index.js:7246:37) Bundling index.android.js 99.5(391/392), failed.

SmallComfort commented 7 years ago

你好! @observer 是装饰器语法,需要你安装 babel 插件 babel-plugin-transform-decorators-legacy ,并在你的 .babelrc 文件下作如下配置

{
  "plugins": [
    "transform-decorators-legacy"
  ]
}

可以参见示例 demo

你也可以不使用装饰器,将 observer 做为函数使用

class Demo extends Component {
  render () {
    return <h1 onClick={store.increase}>{store.count}</h1>;
  }
}

export default observer(Demo)