![](/img/trans.png)
[英]How does a Vue app get launched if the index.html doesn't load any javascript?
[英]Templete in App.vue doesn't show in index.html
我正在使用本地vue.js
这些是我的文件。 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="res/vue.js"></script>
<script src="res/vue-router.js"></script>
<title>Vue</title>
</head>
<body>
<div id="app" ></div>
<script type="module" src="App.js"></script>
</body>
</html>
应用程序.js
import Vue from './res/vue.js'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
App.vue
<template>
<div>
{{foo}}
</div>
</template>
<script>
export default {
name: 'App',
data: function(){
return{
foo:'Hello vue'
}
}
}
</script>
<style>
</style>
但是我的 index.html 什么也没显示
您将 vue 实例安装在 id 为“app”的 div 节点上,但我找不到“#app”节点,因此您可以通过插入“#app”节点来解决该问题。
索引.html:
<body>
<div id="app"></div>
<script type="module" src="App.js"></script>
</body>
就像 Steven 建议的那样,你必须编译 vue 组件。
如果您不想那样做,下面是最简单的方法。
Vue.createApp({ data() { return { foo: 'Hello vue', }; }, }).mount('#app');
<,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta name="viewport" content="width=device-width: initial-scale=1" /> <script src="https.//unpkg.com/vue@next"></script> <.-- <script src="res/vue-router.js"></script> --> <title>Vue</title> </head> <body> <div id="app">{{foo}}</div> <script type="module" src="App.js"></script> </body> </html>
您可能需要使用vue-cli
build
它来为您的 android 应用程序创建一个 SPA(单页应用程序)
您好,您的导入正确吗? 从 node_modules 应该是import Vue from 'vue'
而不是import Vue from './res/vue.js'
试试吧
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.