yoyo930021 / vc2c

The vc2c project can convert vue class APIs to vue composition APIs in Vue.js components written in Typescript.
https://yoyo930021.github.io/vc2c/
MIT License
87 stars 20 forks source link

Discards existing `Vue.extends()` #48

Closed kshksdrt closed 8 months ago

kshksdrt commented 8 months ago

It discards existing Vue.extends() and its contents. For example,

import { Component, Vue } from "vue-property-decorator"
import { useRouter } from "vue-router/composables"

@Component({})
export default class TodoList extends Vue.extend({
  setup() {
    const todoListStore = useTodoListStore();
    const router = useRouter()
    return {
      todoListStore,
      router,
    };
  },
}) {
  @Watch("todoListStore.todos")
  onChange() {
    console.log(this.todoListStore, this.router)
  }
}

becomes

import { useRouter } from 'vue-router/composables'
export default {
  props: {},
  name: 'TodoList',
  setup(props, context) {
    const onChange = () => {
      console.log(
        /* TODO: Check this convert result, it can work well in 80% case.*/ context
          .root.todoListStore,
        /* TODO: Check this convert result, it can work well in 80% case.*/ context
          .root.router
      )
    }
    // TODO: Please remove unused return variable
    return { onChange }
  },
}