[Vuejs]-How to use Compose API in a standalone (one-file) Vue3 SPA?

4👍

✅

You couldn’t use script setup using the CDN, according to official docs:

<script setup> is a compile-time syntactic sugar for using Composition API inside Single File Components (SFCs)

but you could use the setup hook inside the page script as follows :

const {
  createApp,
  ref
} = Vue;
const App = {
  setup() {
    const hello = ref('Bonjour')


    return {
      hello
    }

  }


}
const app = createApp(App)
app.mount('#app')
<script src="https://unpkg.com/vue@3.0.0-rc.11/dist/vue.global.prod.js"></script>

<div id="app">
  {{hello}}
</div>

Leave a comment