javascript - vue2 : Cannot find element: #app

查看:1080
本文介绍了javascript - vue2 : Cannot find element: #app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

第一种

App.vue

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

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0, user-scalable=no">
  <title>vue</title>
</head>
<body>

</body>
</html>

app.js

const app = new Vue({
  router,
  nprogress,
  ...App 
})

app.$mount('#app')

第二种

index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0, user-scalable=no">
  <title>vue</title>
</head>
<body>
<div id="app">
<router-view></router-view>
</div>
</body>
</html>

app.js

const app = new Vue({
  router,
  nprogress,
})

app.$mount('#app')

为什么第一种显示Cannot find element: #app ,而第二种可以?https://github.com/vuejs/vue-... 也是第一种写法,不知道哪里出了问题?

解决方案

第一种,因为挂载的时候找不到id为app的元素

那个项目可以貌似因为是分客户端渲染和服务端渲染的

这篇关于javascript - vue2 : Cannot find element: #app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆