【问题标题】:Vue JS - Using both Vue 2 and Vue 3 in a projectVue JS - 在项目中同时使用 Vue 2 和 Vue 3
【发布时间】:2021-03-10 10:49:11
【问题描述】:

我正在尝试使用在 JS 类组件中定义的函数。为了在组合 api 中使用上述功能,我将执行以下操作:

setup(props) {
  const {errorMessages, handleInput, setFieldData} = Validator.register(props); // function to use

  return {
     errorMessages,
     handleInput,
     input
  }
}

如何使用 vue 2 熟悉的语法做同样的事情?

【问题讨论】:

    标签: javascript vue.js vuejs2 vuejs3 vue-composition-api


    【解决方案1】:

    这大致相当于:

    data() {
      const {errorMessages, handleInput, setFieldData} = Validator.register(this._props);
      
      return {
        errorMessages,
        handleInput,
        input           // undefined btw
      }
    }
    

    您也可以在 Vue 2 中安装 composition api

    npm install @vue/composition-api
    
    import Vue from 'vue'
    import VueCompositionAPI from '@vue/composition-api'
    
    Vue.use(VueCompositionAPI)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-08
      • 2021-04-24
      • 2021-09-15
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2021-05-14
      相关资源
      最近更新 更多