Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix-#144'
Browse files Browse the repository at this point in the history
  • Loading branch information
devilwjp committed Sep 14, 2024
2 parents 199757f + 1e58141 commit 01a4bad
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ First install `@vitejs/plugin-react`, `@vitejs/plugin-vue` and `@vitejs/plugin-v
```js
import { defineConfig } from 'vite'

// if mode cjs, should use `veaury/vite/cjs`
import veauryVitePlugins from 'veaury/vite/esm'

// If mode cjs(vite.config.cjs), should use `veaury/vite/cjs`
// If mode esm(vite.config.mjs), should use `veaury/vite/esm`
// If the configuration file of vite has a `.js` suffix(vite.config.js), it is recommended to import it in the following way.
import veauryVitePlugins from 'veaury/vite'

export default defineConfig({
plugins: [
Expand All @@ -154,8 +155,10 @@ export default defineConfig({
```js
import { defineConfig } from 'vite'

// if mode cjs, should use `veaury/vite/cjs`
import veauryVitePlugins from 'veaury/vite/esm'
// If mode cjs(vite.config.cjs), should use `veaury/vite/cjs`
// If mode esm(vite.config.mjs), should use `veaury/vite/esm`
// If the configuration file of vite has a `.js` suffix(vite.config.js), it is recommended to import it in the following way.
import veauryVitePlugins from 'veaury/vite'

export default defineConfig({
plugins: [
Expand All @@ -182,8 +185,10 @@ Use `vueJsxInclude` and `vueJsxExclude` to configure the file range to be parsed
```js
import { defineConfig } from 'vite'

// if mode cjs, should use `veaury/vite/cjs`
import veauryVitePlugins from 'veaury/vite/esm'
// If mode cjs(vite.config.cjs), should use `veaury/vite/cjs`
// If mode esm(vite.config.mjs), should use `veaury/vite/esm`
// If the configuration file of vite has a `.js` suffix(vite.config.js), it is recommended to import it in the following way.
import veauryVitePlugins from 'veaury/vite'

export default defineConfig({
plugins: [
Expand Down
18 changes: 12 additions & 6 deletions README_zhcn.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ $ npm i veaury -S
```js
import { defineConfig } from 'vite'

// 如果是cjs模式,使用 'veaury/vite/cjs'
import veauryVitePlugins from 'veaury/vite/esm'
// 如果是commonjs模式(vite.config.cjs), 使用 `veaury/vite/cjs` 引入
// 如果是esmodule模式(vite.config.mjs), 使用 `veaury/vite/esm` 引入
// 如果vite的配置文件是`.js`后缀名(vite.config.js), 推荐使用如下的方式引入.
import veauryVitePlugins from 'veaury/vite'

export default defineConfig({
plugins: [
Expand All @@ -113,8 +115,10 @@ export default defineConfig({
```js
import { defineConfig } from 'vite'

// 如果是cjs模式,使用 'veaury/vite/cjs'
import veauryVitePlugins from 'veaury/vite/esm'
// 如果是commonjs模式(vite.config.cjs), 使用 `veaury/vite/cjs` 引入
// 如果是esmodule模式(vite.config.mjs), 使用 `veaury/vite/esm` 引入
// 如果vite的配置文件是`.js`后缀名(vite.config.js), 推荐使用如下的方式引入.
import veauryVitePlugins from 'veaury/vite'

export default defineConfig({
plugins: [
Expand All @@ -132,8 +136,10 @@ export default defineConfig({
```js
import { defineConfig } from 'vite'

// 如果是cjs模式,使用 'veaury/vite/cjs'
import veauryVitePlugins from 'veaury/vite/esm'
// 如果是commonjs模式(vite.config.cjs), 使用 `veaury/vite/cjs` 引入
// 如果是esmodule模式(vite.config.mjs), 使用 `veaury/vite/esm` 引入
// 如果vite的配置文件是`.js`后缀名(vite.config.js), 推荐使用如下的方式引入.
import veauryVitePlugins from 'veaury/vite'

export default defineConfig({
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "veaury",
"private": false,
"version": "2.4.4",
"version": "2.4.5",
"description": "Use React in Vue3 and Vue3 in React, And as perfect as possible!",
"main": "dist/veaury.umd.js",
"module": "dist/veaury.esm.js",
Expand Down
9 changes: 5 additions & 4 deletions src/overrideDom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ const domTopObject = { Document: {}, Element: {} }
export function overwriteDomMethods(refDom) {
Object.keys(domTopObject).forEach((key) => {
domMethods.forEach((method) => {
const old = window[key].prototype[method]
const old = domTopObject[key][method] || window[key].prototype[method]
if (!old) return
domTopObject[key][method] = old
window[key].prototype[method] = function (...args) {
const oldResult = old.apply(this, args)
if (oldResult && (oldResult.constructor !== NodeList || (oldResult.constructor === NodeList && oldResult.length > 0))) return oldResult
// If each function of Document is called using apply, an error will occur. Here you need to use the native function of Element.
if (method === 'getElementById'){
method = 'querySelector'
let currentMethod = method
if (currentMethod === 'getElementById'){
currentMethod = 'querySelector'
args = ['#' + args[0]]
}
const nativeElementFn = domTopObject.Element[method] || Element.prototype[method]
const nativeElementFn = domTopObject.Element[currentMethod] || Element.prototype[currentMethod]
return nativeElementFn.apply(refDom, args)
}
})
Expand Down

0 comments on commit 01a4bad

Please sign in to comment.