Home> Web Front-end> Vue.js> body text

How to use react components in vue

coldplay.xixi
Release: 2020-11-12 15:29:54
Original
3826 people have browsed it

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
Copy after login

2. Edit main.js:

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

3. Add the react components that need to be referenced

import MyReactComponent from './MyReactComponent'
Copy after login

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
Copy after login
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!

Related labels:
vue
source:php.cn
Statement of this Website
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