How Can I use components using CDN in vue.js?

Viewed 43

I am using vue.js as CDN. I need help with a schematic of how I can build an application to display the component in index.html. Currently, I have the following structure:

<div id="app">

</div>
<script>
const { createApp } = Vue
createApp({

  data() {
    return {
      
    }
  
}).mount('#app')
</script>

component.js:

<template>
   <div>
      Test
   </div>
</template>


export default {
    data: () => ({
    }),
 
   
 }
1 Answers

You can try to define Vue and use .component

//in other file
const component1 = {
  template: `<div> {{ item }} <p>{{ prop }}</p></div>`,
  props: ['prop'],
  data: () => ({ item: 'test' }),
}


const app = Vue.createApp({
  data: () => ({ someData: 'prop' }),
})
app.component('test', component1)
app.mount('#app')
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<div id="app">
  <test :prop="someData" />
</div>

Related