Create methods, data state, functions inside setup function 3. 1. Given the same functionality, a component defined via options and a component defined via composition functions manifest two different ways of expressing the same underlying logic. Take the Vue CLI UI file explorer as an example. To apply and automatically re-apply a side effect based on reactive state, we can use the watchEffect API: watchEffect expects a function that applies the desired side effect (in this case, setting innerHTML). It is introduced in order to pass reactive values around as variables without relying on access to this. import { onServerPrefetch } from '@vue/composition-api' export default { setup ( props , { ssrContext } ) { const result = ref ( ) onServerPrefetch ( async ( ) => { result . If you are using refs you will need to remember to add .value to the end of your ref name to access the value.

It is a recommended convention to start the function's name with use to indicate that it is a composition function. Composition functions can also be folded in the editor to make the component much easier to scan: The setup() function now primarily serves as an entry point where all the composition functions are invoked: Granted, this is code that we didn't have to write when using the options API. We intend to ship the API as built-in in 3.0.