Is it possible to import and use the new Composition API in a traditional component which use the Options API?
This is my scenario:
// ComponentA.js
import { reactive } from '@vue/composition-api'
export default {
////////////////////////////////////////////////////////////////
setup() {
//////////////////////////////////////////////
// State
const state = reactive({
isSearching: false,
searchText: '',
isShowMoreResults: false,
resultItems: []
})
//////////////////////////////////////////////
const search = async (searchText) => {
console.log("Searching... ", searchText)
}
//////////////////////////////////////////////
const clear = async () => {
console.log("Clear search")
}
//////////////////////////////////////////////
const nextResults = async () => {
console.log("Next Results")
}
////////////////////////////////////////////////////////////////
return {
state,
search,
clear,
nextResults
}
}
}
I want to use it in my "Options API" style component. How can i import this?
I tried with this but it does not working. The import works fine but i don't know how to call the setup method and get all the exported fields:
import useComponentA from 'ComponentA.js'
let { state } = useComponentA()