Vue.js 3 - No instances of components, really?
P粉790819727
P粉790819727 2023-09-04 15:03:23
0
1
566
<p>In Vue 2, you can create a reactive instance without components, like this: </p> <pre class="brush:php;toolbar:false;">var vue = new Vue({ el: '#root', data: { /*... */ }, methods: { /* ... */ } })</pre> <p>In fact, this is the basic usage pattern introduced at the beginning of the Vue 2 documentation. </p> <p>I think this is a very elegant way to add responsiveness to existing DOM elements, and the instances created are easy to manipulate programmatically. Is there an equivalent method in Vue 3? </p>
P粉790819727
P粉790819727

reply all(1)
P粉293550575

Use CDN

// CDN Vue Import
const { createApp, ref } = Vue

const app = createApp({
  setup() {
    const msg = ref("hello world")
    
    return { msg }
  },
}).mount('#app')
<script src="https://unpkg.com/vue@3.3.4/dist/vue.global.prod.js"></script>

<div id="app">
   <div>{{ msg }}</div>
   <input v-model="msg" />
</div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template