1.2.0 • Published 3 months ago

vue-class-to-vue3-cli v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

vue-class → script setup

TODO: 1. 目前用的zx可能会因为用户没有下载zx导致报错。解决方案:目前考虑有2种 1. 判断用户使用的是npm、pnpm、yarn来在用户install之后通过钩子完成 install zx global。 2. 采用更为通用的命令行调用库(待调研)

依赖zx

如果遇到了 env: zx: No such file or directory 请执行 pnpm install zx -g

使用方式
npm run build
pnpm link --global

vue-class-to-vue3 ${fileName}

需要注意的点:

  1. Mixin 由于在vue3里面已经建议用compositionApi代替,并且在script setup中已经取消了支持,所以无法直接完成转换,可以使用工具对mixin进行转换后更改成compositionApi后手动导入。
  2. vModel在vue2和vue3的双向绑定实现具有差异,请留意转换后是否仍然符合预期。
  3. 不支持 $filters,vue3已经去掉了这个语法,请使用函数代替,工具会帮你进行函数的转换
  4. @Emit(”callback”) callbackFun 的转换只会变成 const emit = defineEmits(’callback’),如果在代码里使用了 callbackFun(), 请自行改为emit(’callback’)。暂时不支持自动转换

目前已经实现的转换

待转换的代码转换后的代码
created在script setup 内相当于直接拿掉 created() {}
mountedonMounted
ClassPropertyref / reactive
Get(classMethod)Computed
vuex-class处理如果存在使用vuex-class,则会删除相应的import。改为使用 import { useStore } from "vuex”。
this.$ || this.去除
vue-routeruseRouter/useRoute
@Component去掉
@PropsdefineProps
<script ><script setup>
函数转为箭头函数
this.$refs.$1const $1 = ref()
@ModeldefineModel
ref和computed在使用时的转换收集所有computed和ref,在使用的后面添加.value
@Ref($1) $2const $2 = ref()
@Emitconst emit = defineEmits
@Component({ props: {} })const {} = defineProps
1.2.0

3 months ago

1.1.9

3 months ago

1.1.8

3 months ago

1.1.7

3 months ago

1.1.6

3 months ago

1.1.5

5 months ago

1.1.1

8 months ago

1.1.0

9 months ago

1.0.15

9 months ago

1.0.14

11 months ago

1.1.3

7 months ago

1.1.2

8 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.11

12 months ago