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"的元素

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM