Answer the question
In order to leave comments, you need to log in
Why is Vue.mount not showing the loaded component?
I'm trying to use Vue3 not through vue create , but to compile through rollup . The problem is that the component is not loaded, that is, the template is deleted after the js is loaded. I can’t find anything on the Internet, almost everything is done through vue create .
My code is:
index.html
...
<div id="app"><p>{{ message }}</p></div>
<script type="text/javascript" src="bundle.js"></script>
...
import { createApp } from 'vue';
const HelloWorlld = {
data() {
return {
message: 'Hello Vue!'
}
}
};
createApp(HelloWorlld).mount('#app');
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
export default {
input: 'main.js',
plugins: [
replace({ "process.env.NODE_ENV": "'production'" }),
nodeResolve({})
],
output: {
file: 'bundle.js',
format: 'iife',
},
};
...
<div id="app" data-v-app=""><!----></div>
<script type="text/javascript" src="bundle.js"></script>
...
Answer the question
In order to leave comments, you need to log in
The case is not so:
createApp(HelloWorlld). $ mount('#app');
?
Found what the problem is.
Vue3 by default comes without a module responsible for processing templates at runtime, which means that I need to "compile" templates at build time.
For rollup there is a plugin rollup-plugin-vue , for webpack there is a vue-loader . You can also use vue-cli to "compile" individual vue components.
The second solution is to use Vue with a templating module. This can be done like this:
import Vue from 'node_modules/vue/dist/vue.esm-bundler';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question