to rewrite some existing HTML that is not SPA with Vue.js components
Vue.js 1.x did the following:
<html>
<body>
<popup></popup>
</body>
</html>
import Vue from 'vue'
import Popup from'./Popup.vue'
new Vue({
el: 'body',
components: {
Popup
}
});
If you write a similar code in Vue.js 2.x, you get the warning Do not mount Vue to <html>or <body>
.
How do we make it happen?
When I tried the following, it seemed that the slot of the component was not configured.
import Vue from 'vue'
import Popup from'./Popup.vue'
new Vue({
el: 'popup',
render —h=>h(Popup)
});
From Vue.js 2.0, you can no longer mount the body.
You can solve this problem if you put a div tag around the part you were mounting on the body.
const Popup={
template: `<p>popup</p>`
}
new Vue({
el: "#app",
components: {
Popup
}
})
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<divid="app">
<popup></popup>
</div>
© 2024 OneMinuteCode. All rights reserved.