lin-xin / vue-manage-system

Vue3、Element Plus、typescript后台管理系统
https://lin-xin.github.io/example/vue-manage-system/
MIT License
18.73k stars 6k forks source link

为什么不使用Composition API?为什么不使用Typescript编码? #292

Open qq1209974887 opened 3 years ago

qq1209974887 commented 3 years ago

既然使用了Vue3.x版本,为什么还在使用Options API而不是官方推荐的Composition API?Vue3本身是使用TypeScript进行编译的,为什么还在大量使用JavaScript代码而不是对类型更加友好的TypeScript?下面是我写的Vue3..0 Composition API代码,本来想参考下你们的代码的组织结构,但现在感觉参考不到了:

export default defineComponent({
  name: 'login',
  components: {
    [Form.name]: Form,
    [Field.name]: Field,
    Header
  },
  setup (props: any) {
    const instance = getCurrentInstance()
    // @ts-ignore
    const ctx: any = instance.ctx

    const state = reactive({
      formGroup: {
        fields: loginConfigs,
      },
    })

    const countDown = (obj: any) => {
      return new Promise((resolve, reject) => {
        const countTimeoutId = setTimeout(async () => {
          let status: any = true
          if (obj.seconds > 1) {
            obj.seconds -= 1;
            status = await countDown(obj);
          }
          clearTimeout(countTimeoutId);
          resolve(status);
        }, 1000);
      })
    }

    const methods = {
      backEvent () {
        ctx.$router.back()
      },
      // 发送短信验证码
      async sendSMSCode (item: any) {
        item.smsCode.status = 'beenSent'
        // 开始倒计时(请求成功之后开始执行)
        const status = await countDown(item.smsCode);
        if (status) {
          item.smsCode.status = 'notSent'
          item.smsCode.seconds = 60
        }
      },
      onSubmit () {
        console.log('提交')
      },
      onFailed (err: any) {
        for (let item of err.errors) {
          if (item.message) {
            ctx.$toast.fail(item.message)
            break;
          }
        }
      },
    }
    return {
      state,
      ...methods
    }
  }
})
chengkai2022 commented 2 years ago

因为不是所有项目都适合全部采用ts吧,ts虽然严谨,但是带来的项目成本有点大,有的项目没必要这样,我猜的

sayid760 commented 2 years ago

已收到,请放心···

xiaoshidetaikuai commented 1 year ago

因为不是所有项目都适合全部采用ts吧,ts虽然严谨,但是带来的项目成本有点大,有的项目没必要这样,我猜的

我完全赞成、、、typescript 把js的优势都搞没了。

sayid760 commented 1 year ago

已收到了···