vue项目根目录下index.html中的id="app",与src目录下的App.vue中的id="app"为什么不会冲突

感谢:https://blog.csdn.net/qq_35624642/article/details/78243413

index.html

<body>
    <div id="app"></div>
    <!-- built files will be auto injected --> 
</body>

App.vue

<template>
  <div id="app">
    <h1 class="title">头部</h1>
    <router-view></router-view>
  </div>
</template>

main.js

new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: {
    App
  }
})

在main.js的初始化中,el:'#app'到底绑定的是哪个文件中的id='app'

 答:将index.htmlid="app"改成其他值,会报错。因此,el: '#app'绑定的是index.html中的id="app"的元素

猜你喜欢

转载自www.cnblogs.com/amunamuna/p/9025081.html
今日推荐