// index.js
import Vue from 'vue'
import App from './app.vue'
new Vue({
el: '#app',
render: (h) => h(App),
});
// app.vue
<template>
<div id="app">
测试
</div>
</template>
<script>
export default {
data: function () {
return {}
},
components: {},
methods: {},
mounted() {},
computed: {}
}
</script>
<style scoped lang="scss">
</style>
问题:
app.vue的内容不能正确渲染出来,为什么??
index.js中用 el: '#app' 的方式挂载dom是否合法??
因为你index.js里挂载的根div“#app”是由vue渲染的一个DOM。在初始化挂载时挂在一个需要初始化后才能拿到的DOM节点自然会失败。