鍍金池/ 問答/HTML/ Vue的掛載點哪里來的

Vue的掛載點哪里來的

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

// index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

// App.vue
<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'app'
}
</script>

初始化一個 Vue 項目的時候會有以上代碼,但是我不知道 main.js 里面的 #app 是指哪一個,是 index.html 里面的 #app 嗎?但是我把這兩個 #app 都改成 #app1 瀏覽器會報錯,說找不到 #app1,這怎么回事?

回答
編輯回答
遲月

html里的app是對應main.js里的

2018年2月12日 19:28
編輯回答
只愛你
// main.js
new Vue({
  el: '#app', //指的是index.html中的<div id="app"></div>
  router,
  template: '<App/>',
  components: { App }
})
2018年4月2日 18:16