Home >Web Front-end >Vue.js >How to use react components in vue

How to use react components in vue

coldplay.xixi
coldplay.xixiOriginal
2020-11-12 15:29:543954browse

Vue uses react components: first install dependencies; then edit [main.js]; finally add the react components that need to be referenced, the code is [import MyReactComponent from './MyReactComponent'].

How to use react components in vue

[Related article recommendations: vue.js]

vue uses react components Method:

1. Install dependencies

npm i -S vuera
npm install --save react react-dom

2. Edit main.js:

import { VuePlugin } from 'vuera'Vue.use(VuePlugin)

3. Add the react components that need to be referenced

import MyReactComponent from './MyReactComponent'

The first problem was discovered at this time:

How to use react components in vue

It is not difficult to find that this is a vue project Caused by the problem of jsx file format

Solution:

Edit webpack.base.conf.js and add support for jsx

test: /\.( js|jsx)(\?.*)?$/

At this time the second problem appeared:

How to use react components in vue

Reason:

## Transform-vue-jsx is introduced by default in the #.babelrc file. This plug-in escapes jsx into the form of h function for vue to call.

Solution:

npm install --save-dev babel-plugin-transform-react-jsx

And replace

transform-vue-jsx# with

transform-react-jsx

in the .babelrc file

## Related free learning recommendations:
JavaScript

(video)

The above is the detailed content of How to use react components in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Does vue.js support ie8?Next article:Does vue.js support ie8?