简体   繁体   中英

Vue JS - Using both Vue 2 and Vue 3 in a project

I'm trying to utilise a function defined in a JS class component. In order to use the said function in composition api I would the following:

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

  return {
     errorMessages,
     handleInput,
     input
  }
}

How can I do the same exact thing but with a syntax that vue 2 is familiar with?

That's roughly the equivalent of:

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

You can alternatively install the composition api in Vue 2:

npm install @vue/composition-api
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'

Vue.use(VueCompositionAPI)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM