vue项目如何使用jsx 写法

924 阅读1分钟

$ npm install babel-plugin-syntax-jsx babel-plugin-transform-vue-jsx babel-helper-vue-jsx-merge-props babel-preset-env --save-dev

npm i babel-plugin-jsx-v-model --save-dev

.babelrc

"plugins": ["transform-runtime","transform-vue-jsx", "jsx-v-model"],

onXXX的均被认为是事件,nativeOnXXX是原生事件,domPropsXXX是Dom属性。

注意 iview 坑壁 有些props 属性是on 开头得 这个时候 就会被认为是个事件 但是其实是个props 属性 导致vue 监听不到 注意 如果是babel7的话 babel一系列插件都得升级 6和7得插件不兼容

"@babel/core": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@babel/preset-stage-0": "^7.0.0",
"babel-loader": "^8.0.6",

.babelrc

"plugins": ["@babel/transform-runtime"]